Skip to content

fix(cli): Stop the wizard with exit code 1 when it has no terminal - #2652

Merged
BYK merged 4 commits into
mainfrom
antonis/wizard-no-terminal
Dec 1, 2026
Merged

BYK merged 4 commits into
mainfrom
antonis/wizard-no-terminal

Conversation

@antonis

@antonis antonis commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Without a terminal, sentry wizard exits 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 abortIfCancelled never runs.

Key Changes

  • The wizard's question prompts (utils/clack/prompts.ts: confirm, select, multiselect, text) go through withRequiredInput. 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 flags sentry wizard --help lists.
  • It fails on that outcome only, not on whether stdin is a terminal. Questions answered by arguments or flags (<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.
  • 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. The check waits for them, so an answered prompt doesn't fail (found by Warden).
  • apps/cli-docs/src/fragments/commands/wizard.md explains what happens without a terminal.
  • New 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:

Case Before After
sentry wizard android < /dev/null Exits 0 at the first question Exit 1 with the message
: | sentry wizard android (pipe already closed) Exits 0 at the first question Exit 1 with the message
printf '\r' | sentry wizard android (one answer, then the end of input) — The answer is accepted, no false message; the Android wizard then stops on its own ("No Gradle project found")
sentry wizard appleSnapshots < /dev/null Runs without a terminal Unchanged

The 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

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

vercel Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cli Ready Ready Preview Dec 1, 2026 12:21pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Dec 1, 2026 12:21pm UTC

Request Review

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely true. Our aim was to allow passing in answers through flags in non-interactive modes so these instructions are a bit misleading.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>>(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer wrappers to start with with as in withRequiredInput or something like that here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to withRequiredInput in b965158.

Comment on lines +105 to +122
@@ -50,7 +119,7 @@ export const clack = {
return log;
},
get multiselect() {
return multiselect;
return failWhenInputEnds(multiselect);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have this get <whatever> indirection here??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not get rid of them somehow?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check this as a follow up 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following up in #2658 ⌛

Comment thread packages/cli/src/lib/wizard/run.ts Outdated
Comment on lines +159 to +163
// 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.`,
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

antonis and others added 2 commits December 1, 2026 13:20
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>
@vercel
vercel Bot temporarily deployed to Preview – sentry-local December 1, 2026 12:21 Inactive
@antonis
antonis marked this pull request as ready for review December 1, 2026 12:39
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Dec 1, 2026
@antonis
antonis requested a review from BYK December 1, 2026 12:42

@BYK BYK left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?)

@BYK
BYK added this pull request to the merge queue Dec 1, 2026
Merged via the queue into main with commit 227f1bd Dec 1, 2026
33 checks passed
@BYK
BYK deleted the antonis/wizard-no-terminal branch December 1, 2026 12:52
@antonis

antonis commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

systematic way to allow every question to be answered via guessable and deterministic flags on the wizard command

Noted 👍

github-actions Bot pushed a commit to Fields-Education/sentry-mcp that referenced this pull request Dec 2, 2026
## 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>

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – cli — 5aae4f9b Deployed Dec 1, 2026 by vercel[bot]
Preview – sentry-local — 5aae4f9b Deployed Dec 1, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants