Repository navigation
fix(cli)!: exit 2 for invalid flag and argument values [RED-1277] [ship] - #1584
Merged
Merged
Conversation
Input that is invalid on its own (a malformed or out-of-range value, or flags that cannot be combined) was often rejected with a plain Error or exit(1), so it exited 1 like a failure. It now exits 2, the usage-error code. Validation helpers throw InvalidInputError, which carries oclif's exit 2. Catch blocks that print their own (JSON) error document take the code from exitCodeFor(err). deploy's flag conflicts and import's --all/--plan-id conflict exit 2. Well-formed input that names something remote that does not exist still exits 1. BREAKING CHANGE: invalid flag and argument values exit 2 instead of 1 in the commands listed in the PR. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Linear: RED-1277
The exit-code contract says 2 is a usage error and 1 is a failure. Many checks that reject input which is invalid on its own (a malformed or out-of-range value, or flags that cannot be combined) threw a plain
Erroror calledexit(1), so they exited 1 like a failure. A script or agent could not tell "fix your arguments" from "something failed". These checks now exit 2.Exit code 1 still covers well-formed input that names something remote that does not exist or does not fit the remote data:
--location,--private-locationor--plan-id;assets downloadneeding--typefor a result with several assets;This matches the treatment of
account plan <unknown key>in RED-1274.How it works
InvalidInputError(helpers/invalid-input-error.ts) carriesoclif = { exit: 2 }. oclif'sCommand.catchand its error handler read the exit code from that field. It prints the same way as before (Error: <message>on stderr). oclif's custom flagparsepath rethrows the same object, sodeploy --schedule-on-deploy-threshold abcexits 2 as well.InvalidInputError:number.ts,usage.ts,result-assets.ts(the source flags),api-fields.ts,flags.ts, and the--detachreporter check intest-helper.ts. So do theassets download --force --skip-existingconflict and theimport planresource specifier.process.exitCode = exitCodeFor(err), which returns 2 for invalid input and 1 otherwise. That covers alert-channels get/logs/list and account usage terms/summary/series/term/projections. Under--output jsonthese still print the JSON error document, now with exit 2.deploy's two flag-conflict checks andimport's--all+--plan-idconflict callexit(2).docs/output-contract.mdandAGENTS.mdnow say which mechanism to use where.Breaking changes (for the v10 release notes)
Invalid input now exits 2 instead of 1:
checkly account usageterms/summary/series/term/projections: invalid dates,--fromafter--to,--cursor,--limit,--pricing-rule/--group-by/--includevalues, an invalid term ID or--account-id,--as-of, and the removed--check-type.checkly alert-channels get/logs/list: a non-numeric ID,--page,--limit,--from, or--to.checkly assets list/download: both or neither of--check-id/--test-session-id.assets downloadalso exits 2 for--forcewith--skip-existing.checkly api -F: a malformed field or invalid JSON.checkly import plan <resource>: an invalid resource specifier.checkly import cancel:--allwith--plan-id.checkly deploy:--no-plancombined with a plan-only flag;--schedule-on-deploy;--schedule-on-deploy-thresholdor--schedule-on-deploy-min-frequency.checkly test/pw-test/trigger --detachwith ajsonorgithubreporter. This also exits 2 when that reporter comes fromcli.reportersin the config, because--detachitself is on the command line.Not covered
An invalid regex in
test --grepor in a file pattern still throws a rawSyntaxError, which exits 1. It is compiled for each check during bundling, after the API calls. Fixing it needs the patterns compiled once up front.Testing
InvalidInputError.deployandimportexits, and an API failure that still exits 1.cli-parse-error.spec.ts):api -F broken,deploy --schedule-on-deploy-threshold abcandimport plan bogus:1each exit 2.🤖 Generated with Claude Code