fix: use the error's oclif exit code when --json is enabled - #1654
Open
mikaelkaron wants to merge 1 commit into
Open
mikaelkaron wants to merge 1 commit into
mikaelkaron wants to merge 1 commit into
Conversation
|
Thanks for the contribution! Unfortunately we can't verify the commit author(s): Mikael Karon <e***@g***.com>. One possible solution is to add that email to your GitHub account. Alternatively you can change your commits to another email and force push the change. After getting your commits associated with your GitHub account, sign the Salesforce Inc. Contributor License Agreement and this Pull Request will be revalidated. |
With --json, Command.catch sets process.exitCode from err.exitCode, which CLIError and
ExitError don't set; they carry their code in err.oclif.exit. So under --json every failure
exits 1: this.error('...', {exit: 2}) and this.exit(3) included. Without --json, handle()
already exits with err.oclif.exit.
catch now prefers err.oclif.exit, then err.exitCode, then 1, so a command exits with the same
code with or without --json. CommandError gains the optional oclif metadata.
mikaelkaron
force-pushed
the
fix/json-exit-code
branch
from
October 1, 2026 16:15
78582ef to
bf35f78
Compare
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.
What does this PR do?
With
--jsonenabled,Command.catchsets the exit code fromerr.exitCode:CLIErrorandExitErrordon't setexitCode; they carry their code inerr.oclif.exit. So under--json, every failure exits with 1:Without
--json,handle()already exits witherr.oclif.exit. A script that checks$?gets a different code depending on whether it asked for JSON.This PR makes
catchprefererr.oclif.exit, thenerr.exitCode, then1:CommandErrorgains the optionaloclifmetadata (Partial<OclifError>), so the type matches whatcatchreceives.Testing
New tests in
test/command/command.test.ts, under--json exit code:this.error(..., {exit: 2})exits 2;this.exit(3)exits 3;exitCode: 4and nooclif.exitstill exits 4;Errorstill exits 1.The first two fail on
main(exit 1) and pass with this change.yarn testpasses (836), and so doyarn lintandtest:circular-deps.