fix(aw-compat): gh aw fix returns exit code 2 and correct summary when guided-error codemod fires#43169
Conversation
… message Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR improves gh aw fix’s behavior when a “guided/manual-fix” codemod fires (e.g., top-level env: secrets): instead of reporting “No fixes needed” with exit code 0, it now emits a manual-fix summary and returns an ExitCodeError{Code: 2} so automation can branch on “manual intervention required”.
Changes:
- Introduces a
GuidedErrorsentinel (withUnwrap) and aCodemod.Guidedflag to classify advisory/manual-fix codemod failures. - Updates
processWorkflowFileWithInfoto wrapApplyerrors fromGuided: truecodemods asGuidedError. - Updates
runFixCommandto count guided errors, suppress “✓ No fixes needed” when present, print a manual-fix summary line, and return exit code2. - Adds tests covering exit code
2, suppression of “No fixes needed”, pluralization, andGuidedErrorwrapping.
Show a summary per file
| File | Description |
|---|---|
| pkg/cli/fix_command.go | Tracks guided/manual-fix codemod errors, adjusts summary output, and returns exit code 2 when manual fixes are required. |
| pkg/cli/fix_command_test.go | Adds regression tests for guided-error exit code + output behavior and for GuidedError wrapping. |
| pkg/cli/fix_codemods.go | Adds Codemod.Guided and the GuidedError sentinel type. |
| pkg/cli/codemod_engine_env_secrets.go | Marks the top-level env secrets codemod as Guided: true. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 4/4 changed files
- Comments generated: 2
- Review effort level: Low
| fmt.Fprintf(os.Stderr, "%s\n", console.FormatErrorMessage(fmt.Sprintf("Error processing %s: %v", filepath.Base(file), err))) | ||
| var guidedErr *GuidedError | ||
| if errors.As(err, &guidedErr) { | ||
| totalGuidedErrors++ | ||
| } |
| if totalFixed > 0 { | ||
| fmt.Fprintf(os.Stderr, "%s\n", console.FormatSuccessMessage(fmt.Sprintf("✓ Fixed %d of %d workflow files", totalFixed, totalFiles))) | ||
| } else { | ||
| } else if totalGuidedErrors == 0 { | ||
| fmt.Fprintf(os.Stderr, "%s\n", console.FormatInfoMessage("✓ No fixes needed")) | ||
| } |
🤖 PR Triage
Score Breakdown
Batch candidate with #43168 (safe-output ingestion hardening). Both are small, clean bug fixes.
|
|
@copilot please run the
|
…nd return exit 1 on hard processing errors Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Done — addressed both unresolved review threads in commit
Three new tests were added: exit code 1 for hard errors, suppression of "No fixes needed" for hard errors, and a mixed-file test verifying |
|
🎉 This pull request is included in a new release. Release: |
gh aw fixwas printing✓ No fixes needed(exit 0) even when a guided-error codemod (e.g.top-level-env-secrets-guided-error) fired, because processing errors caused the file to be skipped before the fix counter was incremented — leaving the summary with zero fixes and a false success signal.Changes
GuidedErrorsentinel type (fix_codemods.go) — new error type withUnwrapsupport; distinguishes manual-fix conditions from hard processing failures.Guided boolfield onCodemod— marks codemods whoseApplyerrors are advisory (not auto-correctable).getTopLevelEnvSecretsGuidedErrorCodemodis the first consumer.processWorkflowFileWithInfo— wraps errors fromGuided: truecodemods as&GuidedError{Cause: ...}so the caller can identify them viaerrors.As.runFixCommandsummary logic:totalGuidedErrorsseparately from auto-fix counts.✓ No fixes neededwhen guided errors are present.✗ N file(s) need a manual fix.&ExitCodeError{Code: 2}— distinct from the crash exit code (1) so automation can branch on this condition.Before / After