Skip to content

fix(cli): give --json the failure text as typed for cloud commands - #8607

Merged
jrusso1020 merged 1 commit into
mainfrom
fix/cli-json-failure-message
Nov 23, 2026
Merged

jrusso1020 merged 1 commit into
mainfrom
fix/cli-json-failure-message

Conversation

@jrusso1020

@jrusso1020 jrusso1020 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

What

A failed --json run of lambda, cloudrun and beats now answers with the failure text as it was given. Before, the JSON message was the line as people see it on the terminal, where a control character in a repeated value is already written out as visible text (\x07), so a program reading the JSON got the escaped form, not the value. The line for people is printed as before: every control character in a repeated value shows as visible text, except a line break, which still prints as a real line break on the terminal.

Why

Other commands already do this through the shared printFailureLine: the terminal line shows control characters as text, the JSON carries the value itself and lets JSON encoding do its own escaping. These three command families printed their failure line directly and were left out.

Related work

Refs #8336. Follows #8603.

How

Nine failure lines move from a direct print to the shared printFailureLine, which prints the same line for people and records the text as given for the --json answer: the unknown subcommand and unknown sites verb of lambda and cloudrun, the missing batch file of cloudrun render-batch, the three stack-file messages of lambda (no stack, unreadable file, file names another stack), and the failure line of beats.

Looked at and left alone, because they print their own JSON on a --json run or print only fixed text: the usage lines of the same commands, lambda policies validate, the render-failed and batch-failed lists of cloudrun, and the failure lines of layout, media-treatment, models, normalize-audio and snapshot. The sign-in commands take no --json.

One thing to know: like every other caller of this helper, a line break inside a repeated value is kept as a line break on the terminal line; every other control character is shown as text.

Test plan

  • Unit tests added/updated
  • Manual testing performed: not run by hand; each line is reached by a test through the CLI's entry point
  • Documentation updated: docs/packages/cli.mdx, "What every command shares": the error.message of a failed --json run carries a repeated value as given
  • Comments follow CONTRIBUTING.md "Comments"

fails without the fix: each of the nine lines was put back to a direct print on its own and one test failed each time; with the change cli.lifecycle.test.ts gives Tests 42 passed (42) and the files for the three commands with it give 205 passed in 18 files. oxfmt, oxlint and tsc --noEmit are clean.

Failure table
A step fails part way Not applicable: the change only formats a message that is about to be printed; no state is written.
Replay or retry Not applicable: the same failure gives the same text.
Concurrent runs Not applicable: no shared state.
Windows The three tests that need a control character in a file name are skipped there, since the file system refuses such names.
Claude Fable 5.2

Notes

  • 159 added lines: 26 in four source files, 3 in the docs page, the rest in the test.
  • Exit codes are unchanged (2 for a usage failure, 1 otherwise); the tests check them.
  • The test body shared by the old and new cases moved into one function; the earlier case for a missing file is unchanged.

🤖 Generated with Claude Code

A failed --json run of lambda, cloudrun and beats answered with the
message as people see it on the terminal, with control characters
already written out as text. The JSON message now carries the value as
it was given; the line for people is unchanged.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mintlify

mintlify Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
hyperframes 🟢 Ready View Preview Nov 23, 2026, 4:43 PM

💡 Tip: Enable Automations to automatically generate PRs for you.

@jrusso1020 jrusso1020 added the needs-jerrai-review Request a review from Jerrai. Removed after the review posts; re-add to request another. label Nov 23, 2026

@miguel-heygen miguel-heygen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed at e6d4154 (one commit, 6 files). There are no other reviews on the PR yet.

Strengths

  • All nine sites go through the shared printFailureLine (utils/jsonError.ts:54) instead of building their own JSON path. A failed --json run therefore gets reported.exact, and its message holds the given value, not the escaped form from the captured stderr.
  • cli.lifecycle.test.ts has one case per moved line (6 via argv, 3 via a written stack file or project), each asserting both sides:
    • the stderr line carries \x07, not the raw BEL;
    • the envelope's error.message carries the raw value, without \\x07;
    • the exit code (2 for the usage lines, 1 otherwise).

Verified

  • Stdout, stderr and exit codes.
    • printFailureLine writes a single console.error and never touches stdout.
    • Every moved site keeps its failUsage() or failCommand() right after it, so the exit codes are unchanged.
    • The visible text is the same template with show in place of terminalText, c.error included.
  • The left-alone set holds up. I audited every remaining failure print in lambda.ts, lambda/*.ts, cloudrun.ts and beats.ts:
    • Fixed usage or required-flag lines with no interpolated value: lambda.ts:300/319/327/371/378/386/427/445 and cloudrun.ts:338/364/511/552/560/623/664/672/683/800.
    • Interpolations that are numbers or the CLI's own constants, never typed text:
      • --fps ... got ${fpsRaw} (lambda.ts:332/391, cloudrun.ts:542) is parsed to an int.
      • The missing-coordinates list at cloudrun.ts:300 is fixed key names.
      • The line ${idx + 1} batch lines (cloudrun.ts:769/777) are numbers.
      • The missing-package and adapter messages (lambda.ts:94, cloudrun.ts:111) take a known subcommand.
    • Lines that a --json run never reaches, because the command prints its own JSON first:
      • render status and errors (cloudrun.ts:610-612);
      • progress errors (cloudrun.ts:640);
      • render-batch failures (cloudrun.ts:752);
      • lambda policies validate (policies.ts:283).
    • lambda/render-batch.ts failures already go through errorBox.
    • The onNotice writes are notices, not failures.

Nit

  • Newlines. printFailureLine shows values through terminalLines, while 8 of the 9 old lines used terminalText (beats.ts already used terminalLines). So a value that contains a newline now prints as a real line break on stderr instead of \x0a: a subcommand, a sites verb, the batch path, the stack name, or the state-file path or reason in lambda/state.ts.
    • That matches how other failure lines in the CLI already show values (failCaught and the existing printFailureLine callers).
    • But it is a visible change for that input, so "the line people see is unchanged" holds only for values without a newline.
    • The one value read from disk is stack.stackName (state.ts:176).
    • Fine to keep; worth one line in the body or a case in the test table.

CI: all 67 check-runs at e6d4154 have completed, each with success or skipped, none failing.

Verdict: APPROVE
Reasoning: Each moved line is pinned on both its stderr form and its --json message, and the exit codes are untouched. Every remaining direct failure print in these commands is fixed text, a number or constant, or sits behind the command's own --json output.

@jrusso1020
jrusso1020 added this pull request to the merge queue Nov 23, 2026
Merged via the queue into main with commit 31be52d Nov 23, 2026
121 checks passed
@jrusso1020
jrusso1020 deleted the fix/cli-json-failure-message branch November 23, 2026 17:20

This branch was successfully deployed

1 active deployment
staging - docs — e6d41540 Deployed Nov 23, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-jerrai-review Request a review from Jerrai. Removed after the review posts; re-add to request another.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants