Repository navigation
fix(cli): Stop the wizard with exit code 1 when it has no terminal - #2652
Conversation
Without a terminal, `sentry wizard` exited 0 at its first question, as if it had finished. Clack doesn't handle the end of its input: the prompt never settles, the event loop empties, and Node exits 0. The React Native wizard installs the SDK before its first question, so this left a half-done setup that looked like success. - `runWizard` fails before anything changes when stdin is `/dev/null` or closed, except for Apple Snapshots, which has a mode without a terminal. A pipe or a file may still hold answers. - The wizard's clack prompts stop the wizard with exit code 1 and a message when stdin ends before they are answered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
When the last answer and the end of stdin arrive in the same read, the stream emits `end` before the prompt's promise callbacks run, so the wizard printed "its input ended" and tagged `no-input` although the answer counted. Decide after those callbacks, and fail only when the prompt is still unanswered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| (`/dev/null` or closed, as in CI or a coding agent's shell), it stops with | ||
| exit code 1 before changing anything, except for `appleSnapshots`. Answers | ||
| can also be piped in; if the input ends before a question, the wizard stops | ||
| there with exit code 1. To have a coding agent set up Sentry instead, run |
There was a problem hiding this comment.
Not entirely true. Our aim was to allow passing in answers through flags in non-interactive modes so these instructions are a bit misleading.
There was a problem hiding this comment.
Agreed, reworded in b965158. The paragraph now says that without a terminal the wizard skips the questions its arguments and flags answer (<org>/<project>, the integration, --app-target), and only stops, with exit code 1, when it reaches a question nothing answered and its input has ended. The error message points to flags too.
| * already installed packages. Input that is piped and still open, such as the | ||
| * wizard e2e tests' answers, keeps working. | ||
| */ | ||
| function failWhenInputEnds<F extends (...args: never[]) => Promise<unknown>>( |
There was a problem hiding this comment.
I prefer wrappers to start with with as in withRequiredInput or something like that here.
There was a problem hiding this comment.
Renamed to withRequiredInput in b965158.
| @@ -50,7 +119,7 @@ export const clack = { | |||
| return log; | |||
| }, | |||
| get multiselect() { | |||
| return multiselect; | |||
| return failWhenInputEnds(multiselect); | |||
There was a problem hiding this comment.
Why do we have this get <whatever> indirection here??
There was a problem hiding this comment.
The getters came with the wizard port (#2519). Many of the ported tests mock @clack/prompts with only the functions they use, and Vitest throws when a missing mock export is read, so the getters read clack only when it's called.
There was a problem hiding this comment.
I'll check this as a follow up 👍
| // Apple Snapshots has a mode without a terminal (`nonInteractive`). | ||
| if (args.integration !== "appleSnapshots" && !stdinCanAnswer()) { | ||
| throw new CliError( | ||
| `${sentry`wizard`} asks questions, but its input is empty (no terminal). Run it in an interactive terminal, or run ${sentry`init`} to have a coding agent set up Sentry.`, | ||
| ); |
There was a problem hiding this comment.
This is a dangerous check as there might be other commands that can work non-interactively. Also see my comment above.
We should fail on the expected outcomes: we needed an input and it was not provided (through an interactive prompt or a flag) not static command names.
There was a problem hiding this comment.
Agreed, removed in b965158, with the Apple Snapshots exception. The wizard now fails only on the outcome: a prompt needs an answer and stdin has ended. Answers given as flags or arguments never reach a prompt, so they keep working without a terminal. The trade-off: with /dev/null, the React Native wizard installs the SDK before failing at its first question. That run now ends with exit 1 and a message instead of exit 0.
Drop the up-front stdin check in `runWizard` and its Apple Snapshots exception: the wizard now stops with exit code 1 only when a prompt needs an answer and its input has ended, so flags and arguments that answer the questions keep working without a terminal. Rename the prompt wrapper to `withRequiredInput`, and reword its message and the docs to mention flags. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BYK
left a comment
There was a problem hiding this comment.
As a follow up we should come up with a good and systematic way to allow every question to be answered via guessable and deterministic flags on the wizard command (and maybe for others too?)
Noted 👍 |
## Summary Follow-up to the review on getsentry#2652: a systematic way to answer wizard questions with guessable, deterministic flags. This PR adds the mechanism and covers the yes/no feature questions the wizards share. `sentry wizard` gets `--tracing`, `--replay`, `--logs`, `--profiling`, `--instrumentation-api` (reactRouter), `--example-page` and `--example-component`. `--<flag>` answers yes and `--no-<flag>` answers no, in every wizard that asks the question. A flag that isn't set still asks. An answered question is logged (`Session Replay: no (--no-replay)`), so the run's output still shows it. ```sh sentry wizard my-org/my-app nextjs --tracing --no-replay --no-example-page ``` ### How it stays systematic - One registry, `WIZARD_ANSWER_FLAGS` (`lib/wizard/utils/answers.ts`), holds each flag's label and the wording of its question. The prompt (`askFlagQuestion`), the flag's `--help` text and the log line are all built from it, so they can't diverge. The command builds its flags from the registry, so `--help`, the docs and the skill reference list them with no extra step. - `askFlagQuestion(flag, hints)` asks a question unless its flag answered it. `sentry wizard` stores the parsed flags once, before the first flow starts, so flows don't pass them along and a flow that hands over to another wizard (sourcemaps redirecting to SvelteKit or React Native) keeps them. - `Feature.flag` is required and `Feature.prompt` is gone, so every `featureSelectionPrompt` entry takes its wording from its flag. The Android and React Native Logs/Replay questions use the same shared wording, and their docs links move into hints. - `design/sentry-cli.md` gets the naming rule, plus a gap for the questions that still have no flag. - The `@stricli/core` patch fixes `undoNegation` for kebab-case names. It cut one character too many after `no-`, so a negated multi-word flag such as `--no-example-page` was rejected even though `--help` listed it. ### Scope The wizards have about 78 prompt sites. They fall into four groups: | Kind | Examples | Plan | | -- | -- | -- | | Feature choices | tracing, replay, logs, example page | This PR | | Value choices | package manager, Next.js tunnel route, CI, MCP editors, PII reduction, RN feedback widget, `pod install`, formatters | Follow-ups with the same registry, as hidden flags where `--help` would get noisy | | Safety confirms | dirty git, unsupported version, "modify anyway?" | Already `--force` | | Manual-step acks | "Did you copy the snippet above?", "Did you add the code…?" (~15) | No flag. Without a terminal, these should print the remaining steps and exit non-zero, tied in with `sentry init` | Once getsentry#2652 lands, its no-input message can name the exact flag for the unanswered question, read from the same registry. Part of getsentry#2642. <!-- junior-request-attribution:start --> via @BYK. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:local%3Aweb%3Ad6ffaea810846e1ab576fcc3 --> -- [View Session](https://junior-prod.sentry.dev/conversations/local%3Aweb%3Ad6ffaea810846e1ab576fcc3) [[Sentry]](https://sentry.sentry.io/explore/conversations/local%3Aweb%3Ad6ffaea810846e1ab576fcc3/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: BYK <126780+BYK@users.noreply.github.com> Co-authored-by: BYK <burak.kaya@sentry.io>
Summary
Without a terminal,
sentry wizardexits 0 at the first question nothing answered, as if it had finished. The React Native wizard installs the SDK before its first question, so a run in CI or a coding agent's shell leaves a half-done setup that looks like success.Root cause
Clack doesn't handle the end of its input. When stdin ends, the prompt's promise never settles, Node's event loop empties, and the process exits 0. It isn't a cancel, so
abortIfCancellednever runs.Key Changes
utils/clack/prompts.ts:confirm,select,multiselect,text) go throughwithRequiredInput. When a prompt needs an answer and stdin has ended, the wizard stops there with exit code 1 and a message pointing to an interactive terminal, or to the flagssentry wizard --helplists.<org>/<project>, the integration,--app-target) never reach a prompt, so they keep working without a terminal. Answers piped through an open stdin, as the wizard e2e harness does, keep working too.endbefore the prompt's promise callbacks run. The check waits for them, so an answered prompt doesn't fail (found by Warden).apps/cli-docs/src/fragments/commands/wizard.mdexplains what happens without a terminal.test/lib/wizard/utils/clack/prompts-input-end.test.ts: input ends before the answer (exit code 1 and the message), an answered prompt returns its value, and input that ends right after the answer doesn't fail it.Verification
With the built npm package (
dist/bin.cjs), in a directory that isn't a git repository, so the first question is the git warning:sentry wizard android < /dev/null: | sentry wizard android(pipe already closed)printf '\r' | sentry wizard android(one answer, then the end of input)sentry wizard appleSnapshots < /dev/nullThe bundle smoke tests from #2603 (every wizard started with a closed stdin pipe) still pass.
One thing to accept: the React Native wizard installs the SDK before its first question. Run with
/dev/null, it still installs it, then stops at that question with exit code 1 and the message, instead of exit 0. I didn't run this case, since it installs from npm.Part of #2642.
🤖 Generated with Claude Code