fix(cli): mask sensitive values in API error output
TR
1h ago+581+581+012345678901234567890123456789-21-21-01234567890123456789
Why
--debug masks values the API description marks sensitive (x-speakeasy-param-sensitive, format: password) when it logs a response body. The normal error output did not: when an API error body echoed a sensitive value, it was printed as-is in the pretty Details: block, the error message line, and the -o json / agent-mode error envelope.
What changed
Classifynow passes the error body through the SDK'sredact.ResponseBody, the same masking--debuguses. The operation comes from the response's request context, or from the command when the error carries no HTTP response (for example typed error models that keep only their schema fields). Operations split per request content type generate one SDK method per variant, and the masking rules are keyed by that method's ID, so such commands now carry aspeakeasy_sdk_operationannotation that the lookup prefers over the originalspeakeasy_operation. Other commands are unchanged.- The error message and the envelope
errortext are held to the same redaction when they fall back to the error's own text: a raw body embedded in that text is replaced by the masked body, a typed error model's JSON rendering is replaced by the masked body, and any other occurrence of a value that masking replaced is masked too (for example a typed error whoseError()returns a single sensitive message field). - When the error has no response body but is a generated error model, the model's own fields are checked against the operation's sensitive fields for that last step.
- Generated only when the document has sensitive values (
hasAnyRedactGraphs); other CLIs are unchanged. - Successful command output is unchanged and still shows decoded values.
- Like
--debug, a body that cannot be parsed for an operation with sensitive response values is masked as a whole. - Test fixtures (CLI-only):
cliSensitiveResponseGetgains a400response that reuses its sensitive schema;cliSensitiveErrorMessageGetreturns a400whosex-speakeasy-error-messagefield is sensitive;cliSensitiveSplitResponsePostis split into form and multipart methods and returns a sensitive400.
Testing
- New
TestErrorOutputRedactsSensitiveResponseFields(pretty,-o json, agent mode): a 400 echoing a sensitive value never shows it, while the unmarked sibling stays readable. It failed in all three modes before the change. - New
TestRedactedMessageDropsMaskedValuesfor the message fallback cases, including a message that is a masked field and values under a masked subtree. - New
TestErrorOutputRedactsSensitiveErrorMessageField(pretty,-o json, agent mode) andTestErrorOutputRedactsSensitiveFieldsOfSplitOperation(both split commands). Each fails with its part of the fix removed. TARGET=review make test-cli,TARGET=primary make test-cli,make check-template-cli,npm run format,go test ./pkg/generate/snapshots/ -run TestSnapCLIandgit diff --checkpass.
Public-safety check
- This change contains no credentials, customer documents, private repository URLs, private filesystem paths, or unredacted private logs.
- Title, body, comments, and commit messages name no customers or customer-derived identifiers, private paths or trackers, or workflow provenance, and are understandable without private context (
.claude/skills/public-repo-communication/SKILL.md). - Generated fixtures and review SDK changes are public-safe.
- I reviewed
git diff --check.
Summary by cubic
Masks API-marked sensitive values in CLI error output, matching --debug. Previously, echoed values could appear in the Details: block, fallback error messages, and -o json or agent-mode envelopes; successful output is unchanged.
- Redacts error bodies using the operation's schema, including commands for operations split by request content type.
- Also scrubs fallback error text and machine-readable
errorfields, preserving numeric spelling. - Only generated CLIs with sensitive values are affected.