sentry-cli
sentry-cli copied to clipboard
Exit code ignored with `SentryCli.execute([...], true)` (live mode)
CLI Version
2.31.2
Operating System and Architecture
- [X] macOS (arm64)
- [ ] macOS (x86_64)
- [ ] Linux (i686)
- [X] Linux (x86_64)
- [ ] Linux (armv7)
- [ ] Linux (aarch64)
- [ ] Windows (i686)
- [ ] Windows (x86_64)
Operating System Version
Ubuntu 20.4 & MacOS 14.4.1
Link to reproduction repository
No response
CLI Command
No response
Exact Reproduction Steps
Run the following in a node REPL: node -i
> const SentryCli = require('@sentry/cli')
undefined
> await new SentryCli().execute(['does not exist'], true)
error: unrecognized subcommand 'does not exist'
Usage: sentry-cli [OPTIONS] <COMMAND>
For more information, try '--help'.
undefined
Note that under the hood, sentry-cli
's exit code is 2
in this context.
Expected Results
I expect the execute([...], true)
function to throw an Error that I can catch and react to. It does throw an error when the second argument is false
but not when it's set to true
.
Actual Results
No errors are thrown, the command ends as if everything was OK
Logs
There are no logs in this context
Hi @dotboris, the problem appears to be that you are running the command with live = true
(the second parameter passed to SentryCLI().execute
. If you replace the call with the following, you will observe that the error is raised:
> await new SentryCLI().execute(['does not exist'])
Uncaught:
Error: Command failed: /Users/dszoke/node_modules/@sentry/cli-darwin/bin/sentry-cli does not exist
error: unrecognized subcommand 'does not exist'
Usage: sentry-cli [OPTIONS] <COMMAND>
For more information, try '--help'.
at __node_internal_genericNodeError (node:internal/errors:866:15)
at ChildProcess.exithandler (node:child_process:422:12)
at ChildProcess.emit (node:events:514:28)
at ChildProcess.emit (node:domain:551:15)
at maybeClose (node:internal/child_process:1105:16)
at ChildProcess._handle.onexit (node:internal/child_process:305:5)
at Process.callbackTrampoline (node:internal/async_hooks:130:17) {
code: 2,
killed: false,
signal: null,
cmd: '/Users/dszoke/node_modules/@sentry/cli-darwin/bin/sentry-cli does not exist'
}
We should likely clarify the execute
function's documentation comment to clarify that running with live=true
suppresses any errors.
Thank you for pointing that out. In my case, I find the live
option useful in my usecase. I believe that we should still get an error in this case as well. I'll update the issue to clarify.
Hi @dotboris, can you please clarify why you need the live
option? What does this option provide that you cannot achieve otherwise?
The live
option streams the output of the sentry command directly to my process's stdout. This is the behaviour that I'm after. I'm writing a CLI that injects debug ids into my artifacts and then uploads them to sentry. The live
option lets users see the output from the sentry cli as it happens.
Okay, appreciate the clarification! I will see whether we can fix this behavior and respond once I have more information
@dotboris Sorry for the delayed response here, this issue got buried.
I don't think we should change the behavior of SentryCli.execute
to result in an error when called with live=true
, since this would potentially be a breaking change for anyone who depends on the current behavior.
I would suggest that you simply call the Sentry CLI binary directly from the script that you are writing. There is likely no need to use the SentryCli.execute
JavaScript abstraction for your use case. Calling the binary directly will offer you the greatest flexibility in determining how to respond to outputs and exit codes.
Hope that helps, please let me know if you have any questions!