Repository navigation
fix(cli): give --json the failure text as typed for cloud commands - #8607
Merged
Merged
Conversation
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>
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
miguel-heygen
approved these changes
Nov 23, 2026
miguel-heygen
left a comment
Collaborator
There was a problem hiding this comment.
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--jsonrun therefore getsreported.exact, and its message holds the given value, not the escaped form from the captured stderr. cli.lifecycle.test.tshas 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.messagecarries the raw value, without\\x07; - the exit code (2 for the usage lines, 1 otherwise).
- the stderr line carries
Verified
- Stdout, stderr and exit codes.
printFailureLinewrites a singleconsole.errorand never touches stdout.- Every moved site keeps its
failUsage()orfailCommand()right after it, so the exit codes are unchanged. - The visible text is the same template with
showin place ofterminalText,c.errorincluded.
- The left-alone set holds up. I audited every remaining failure print in
lambda.ts,lambda/*.ts,cloudrun.tsandbeats.ts:- Fixed usage or required-flag lines with no interpolated value:
lambda.ts:300/319/327/371/378/386/427/445andcloudrun.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:300is 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
--jsonrun 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).
- render status and errors (
lambda/render-batch.tsfailures already go througherrorBox.- The
onNoticewrites are notices, not failures.
- Fixed usage or required-flag lines with no interpolated value:
Nit
- Newlines.
printFailureLineshows values throughterminalLines, while 8 of the 9 old lines usedterminalText(beats.tsalready usedterminalLines). 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 inlambda/state.ts.- That matches how other failure lines in the CLI already show values (
failCaughtand the existingprintFailureLinecallers). - 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.
- That matches how other failure lines in the CLI already show values (
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.
Merged
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A failed
--jsonrun oflambda,cloudrunandbeatsnow 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--jsonanswer: the unknown subcommand and unknownsitesverb oflambdaandcloudrun, the missing batch file ofcloudrun render-batch, the three stack-file messages oflambda(no stack, unreadable file, file names another stack), and the failure line ofbeats.Looked at and left alone, because they print their own JSON on a
--jsonrun or print only fixed text: the usage lines of the same commands,lambda policies validate, the render-failed and batch-failed lists ofcloudrun, and the failure lines oflayout,media-treatment,models,normalize-audioandsnapshot. 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
docs/packages/cli.mdx, "What every command shares": theerror.messageof a failed--jsonrun carries a repeated value as givenfails 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 changecli.lifecycle.test.tsgivesTests 42 passed (42)and the files for the three commands with it give 205 passed in 18 files.oxfmt,oxlintandtsc --noEmitare clean.Claude Fable 5.2
Notes
🤖 Generated with Claude Code