Skip to content

fix(cli): Send command hints to stderr when stdout is piped - #2594

Merged
BYK merged 2 commits into
mainfrom
byk/hints-stderr-when-piped
Nov 30, 2026
Merged

BYK merged 2 commits into
mainfrom
byk/hints-stderr-when-piped

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2531

In human mode, the command wrapper (writeFinalization in packages/cli/src/lib/command.ts) wrote a command's returned hint to stdout whenever --json was off, even when stdout was not a TTY. Scripts that capture the output of sentry release propose-version got the version plus a "Detected from git HEAD" line, and worked around it by piping through head -n 1, which hides a failing exit code.

Now the hint goes to stdout only when stdout is a TTY, and to stderr otherwise. The check reads isTTY on the context's stdout writer, as sentry api already does. It applies to every command that returns a hint, including pagination, dry-run, and cache-age footers.

  • Renderers with finalize(), such as the streaming log table, still close their output on stdout, but get no hint when piped.
  • Empty-state messages returned as hints, such as "No logs found", also go to stderr when stdout is piped, so piped stdout is empty when there is no data.
  • --json output is unchanged.
  • SDK calls in text mode capture stdout without isTTY, so their hints also leave the captured text. JSON-mode SDK calls are unaffected.

The design doc, packages/cli/AGENTS.md, and the CLI docs describe the new rule.

Once this ships, callers that use head -n 1 can drop it: the sentry wizard port in #2529 and getsentry/sentry#132671.

via @BYK.

--

View Session [Sentry]

The command wrapper wrote a command's returned hint to stdout whenever
--json was off, even when stdout was not a TTY. So
`$(sentry release propose-version)` captured the version plus a
"Detected from git HEAD" line, and scripts piped through `head -n 1`,
which hides a failing exit code.

writeFinalization now writes the hint to stdout only when stdout is a
TTY. Otherwise it goes to stderr. A renderer's finalize() still runs on
stdout, without the hint, so streaming tables keep their footer. JSON
mode is unchanged.

Test mocks that assert a hint on stdout now model a terminal.

Fixes #2531

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
@vercel

vercel Bot commented Nov 30, 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 Nov 30, 2026 10:30am UTC
1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Nov 30, 2026 10:30am UTC

Request Review

Piped stdout no longer carries hints (#2531), so the e2e run sees the
"No logs found" notice on stderr.
@vercel
vercel Bot temporarily deployed to Preview – sentry-local November 30, 2026 10:30 Inactive
@sentry-junior
sentry-junior Bot marked this pull request as ready for review November 30, 2026 10:47
@sentry-junior
sentry-junior Bot requested a review from BYK November 30, 2026 10:47
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 30, 2026
@BYK
BYK added this pull request to the merge queue Nov 30, 2026
Merged via the queue into main with commit 337c8a6 Nov 30, 2026
43 checks passed
@BYK
BYK deleted the byk/hints-stderr-when-piped branch November 30, 2026 11:02
sentry-junior Bot added a commit that referenced this pull request Nov 30, 2026
Keeps --allow-empty skipping a missing (ENOENT) directory alongside
main's --wait/--no-wait and --no-rewrite changes. The two tests that
read the missing-directory hint now read stderr, since #2594 sends hints
there when stdout is not a TTY.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – cli — 865f1875 Deployed Nov 30, 2026 by vercel[bot]
Preview – sentry-local — 865f1875 Deployed Nov 30, 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.

Command hints print to stdout when output is piped

1 participant