sentry-cli icon indicating copy to clipboard operation
sentry-cli copied to clipboard

Exit code ignored with `SentryCli.execute([...], true)` (live mode)

Open dotboris opened this issue 9 months ago • 5 comments

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

dotboris avatar May 07 '24 14:05 dotboris

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.

szokeasaurusrex avatar May 08 '24 07:05 szokeasaurusrex

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.

dotboris avatar May 08 '24 14:05 dotboris

Hi @dotboris, can you please clarify why you need the live option? What does this option provide that you cannot achieve otherwise?

szokeasaurusrex avatar May 10 '24 10:05 szokeasaurusrex

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.

dotboris avatar May 10 '24 10:05 dotboris

Okay, appreciate the clarification! I will see whether we can fix this behavior and respond once I have more information

szokeasaurusrex avatar May 10 '24 11:05 szokeasaurusrex

@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!

szokeasaurusrex avatar Dec 10 '24 17:12 szokeasaurusrex