Skip to content
Prev Previous commit
Next Next commit
Address review feedback on classifier and env formatting refactor
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
  • Loading branch information
Copilot and pelikhan authored Aug 16, 2026
commit 3ef7e0d0137a0e07d9997e8a7ecd173595f80b48
1 change: 1 addition & 0 deletions pkg/cli/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ func isPermissionErrorStr(s string) bool {
}
lower := strings.ToLower(s)
return strings.Contains(lower, "exit status 4") ||
strings.Contains(lower, "permission") ||
strings.Contains(lower, "gh auth login") ||
strings.Contains(lower, "to use github cli in a github actions workflow")
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/cli/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/github/gh-aw/pkg/console"
"github.com/github/gh-aw/pkg/constants"
"github.com/github/gh-aw/pkg/errorutil"
"github.com/github/gh-aw/pkg/logger"
"github.com/github/gh-aw/pkg/parser"
"github.com/github/gh-aw/pkg/stringutil"
Expand Down Expand Up @@ -273,8 +272,7 @@ func isTransientSHAResolutionError(err error) bool {
}

errorText := strings.ToLower(err.Error())
if errorutil.IsRateLimitError(errorText) ||
strings.Contains(errorText, "http 429") ||
if strings.Contains(errorText, "http 429") ||
strings.Contains(errorText, "rate limit") ||
strings.Contains(errorText, "timeout") ||
strings.Contains(errorText, "timed out") ||
Expand Down
1 change: 0 additions & 1 deletion pkg/errorutil/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func IsGoneError(err error) bool {
// The check is case-insensitive and matches known API phrases.
func IsRateLimitError(output string) bool {
matched := containsSubstring(output,
"api rate limit exceeded",
"rate limit exceeded",
"secondary rate limit",
)
Expand Down
14 changes: 8 additions & 6 deletions pkg/workflow/step_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,16 @@ func StepsToSlice(steps []*WorkflowStep) []any {

// marshalEnvValue serializes a non-string env var value to a string suitable
// for use in a GitHub Actions step env block.
// Arrays and maps are serialized as JSON (e.g. ["a","b"]) so that shell
// consumers such as `jq --argjson` receive valid JSON.
// Typed slices produced by goccy/go-yaml (e.g. []string instead of []any)
// are normalized via reflection before marshaling.
// Scalar values (int, bool, float64, etc.) fall back to fmt.Sprint.
// Arrays and maps are serialized as JSON (e.g. ["a","b"]) via
// importinpututil.FormatResolvedValue so import substitutions and env
// serialization stay aligned. Scalar values (int, bool, float64, etc.)
// fall back to fmt.Sprint.
func marshalEnvValue(v any) string {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/codebase-design] marshalEnvValue now silently returns "" when FormatResolvedValue returns (_, false) and v == nil is false — i.e. it falls through to fmt.Sprint(v). But FormatResolvedValue returns false only for nil; all other types return true. The double-nil guard (if s, ok := ...; ok then if v == nil) therefore creates a dead-code branch: the second if v == nil is unreachable because FormatResolvedValue(nil) returns ("", false) so the first branch doesn't return, but then v == nil is true.

This means nil returns "" correctly, but the structure is confusing — a future FormatResolvedValue change that returns false for non-nil values (e.g. a marshalling error) would silently fall into fmt.Sprint.

💡 Suggested fix

Either log/surface the marshalling failure, or be explicit:

func marshalEnvValue(v any) string {
    if v == nil {
        return ""
    }
    if s, ok := importinpututil.FormatResolvedValue(v); ok {
        return s
    }
    return fmt.Sprint(v)
}

This makes the nil guard first-class and the fallback readable.

@copilot please address this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the nil guard before FormatResolvedValue in aaec1b1.

if s, ok := importinpututil.FormatResolvedValue(v); ok {
return s
}
return ""
if v == nil {
return ""
}
return fmt.Sprint(v)
}
Loading