feat(cli): exit non-zero when error diagnostics are emitted#113
Merged
Conversation
Closes #98. The build CLI previously always exited with status 0 regardless of diagnostic severity, so pre-commit hooks that hide stdout could silently let broken workflows through. The CLI now sets process.exitCode = 1 when any diagnostic at error or fatal severity (after applying configured rules) is emitted. Users can downgrade specific codes via diagnostics.rules, suppress at call sites via Diagnostics.suppress, or disable the behaviour globally via the new diagnostics.failOnError config flag (defaults to true).
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
bcheidemann
reviewed
May 14, 2026
Collaborator
bcheidemann
left a comment
There was a problem hiding this comment.
Sorry, I'm a bit late to the party, as I see this has already merged.
I've left a couple comments but overall this looks great :) Nice work!
Lmk if you'd like me to pick up either of the suggested changes.
| ```json | ||
| { | ||
| "diagnostics": { | ||
| "failOnError": true |
Collaborator
There was a problem hiding this comment.
Some devs prefer to configure their tools to fail on warnings. I wonder if this should be:
"maxSeverity": "info" // fails on warnings and aboveOr
"failOnSeverity": "warn" // fails on warnings and above
Comment on lines
+35
to
+41
| /** | ||
| * Whether any diagnostic at `error` or `fatal` severity (after applying | ||
| * configured rules) has been emitted through this reporter. | ||
| */ | ||
| get hasErrors(): boolean { | ||
| return this._hasErrors | ||
| } |
Collaborator
There was a problem hiding this comment.
Should we add this to the Diagnostics.DiagnosticsReporter interface? This would ensure this is implemented if we (or anyone else) ever implements another reporter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #98.
The build CLI previously always exited with status
0regardless of diagnostic severity, so pre-commit hooks (which often hide stdout) could silently let broken workflows through. This PR makes the CLI setprocess.exitCode = 1when any diagnostic aterrororfatalseverity is emitted during a build, after configureddiagnostics.ruleshave been applied.A new
diagnostics.failOnErrorconfig flag (defaults totrue) lets users opt out for the pre-2.6.0 behaviour. Individual codes can still be downgraded viarulesor suppressed at call sites viaDiagnostics.suppress/suppressWarnings— those existing escape hatches behave exactly as before.process.exitCodeis set rather than callingprocess.exit(1)so any pending IO flushes cleanly before Node exits.What a reviewer should look at
packages/cli/src/commands/diagnostics.ts—ConsoleDiagnosticsReporternow tracks a_hasErrorsflag (exposed via ahasErrorsgetter) that flips insideemit()when the effective severity (post-rules) iserrororfatal. Suppressed (off) diagnostics never flip it, and rule-downgraded errors don't either.packages/cli/src/commands/build.ts— captures the reporter instance, and at the end ofgenerateWorkflowFileschecksreporter.hasErrors && (config.diagnostics?.failOnError ?? true). Settingprocess.exitCodelets yargs and async work unwind naturally.packages/cli/src/commands/types/build.ts— adds thefailOnError?: booleanfield toDiagnosticsConfigwith a doc comment describing the default and the escape hatches.packages/cli/src/commands/diagnostics.spec.ts— newhasErrorsdescribe block covers: default-false, sub-error severities, error/fatal flip, rule downgrade keeps it false, rule upgrade flips it, ruleoffkeeps it false, and stickiness (once flipped, stays flipped).packages/cli/src/commands/build.integration.spec.ts— two layers of tests. The first uses__mocks__/{error,warning}-emitting.fixture.tsto driveimportWorkflowFileend-to-end and verify the reporter state. The second creates a temp project (with a symlinkednode_modulesso the workspace lib resolves),process.chdirs into it, runs the realgenerateWorkflowFiles, and assertsprocess.exitCodefor the error path, the warning-only path, and thefailOnError: falseopt-out.__mocks__/*.fixture.ts— note the.fixture.tssuffix (not.wac.ts). The CLI's*.wac.tsglob shouldn't pick these fixtures up during the repo's own pre-commit build, otherwise the error-emitting fixture would fail every commit. The integration test that exercises the full CLI flow copies the fixture content into a tempwf.wac.tsso it gets discovered there.docs/docs/guides/configuration.md— corrects the (previously inaccurate) claim that severity"error""fails the build", adds afailOnErrorsubsection, and links the two together.docs/docs/guides/typed-actions.md— adds a "Build Exit Code" section right after the suppression docs so the workflow author sees exactly whaterrorseverity means for CI/pre-commit.Test Plan
pnpm -r test— 302/302 pass (lib 97, cli 85, actions 120)pnpm exec eslint packages/cli/src/commands/— cleanpnpm -r build— clean*.wac.tsglobBackwards compatibility
This is a behavior change visible to anyone running the CLI: builds that previously succeeded silently with
error-severity diagnostics will now exit non-zero. The escape hatch (diagnostics.failOnError: false) is one-line and is documented. Suggest a minor version bump (2.6.0).