chore: render CLI errors as TOON - #7239
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
This comment has been minimized.
This comment has been minimized.
942bfb8 to
fd68885
Compare
This comment has been minimized.
This comment has been minimized.
|
product update: probably you may add the conflicting flags validation. In such case, the error will be shown as standard output. (From the pitch) |
fd68885 to
a5f969f
Compare
This comment has been minimized.
This comment has been minimized.
a5f969f to
28d077d
Compare
This comment has been minimized.
This comment has been minimized.
28d077d to
d27abbe
Compare
This comment has been minimized.
This comment has been minimized.
robertolopezlopez
left a comment
There was a problem hiding this comment.
Hi,
It looks good to me. The change is tight. I have also done manual validation and it does what it should. Just one not blocking observation.
Approved
This comment has been minimized.
This comment has been minimized.
fdb64ea to
0c0391d
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
b999b5d to
79e329d
Compare
| func validateOutputFormatSelection(config configuration.Configuration, cmd *cobra.Command) error { | ||
| if config.GetBool(constants.SNYK_FORCE_LEGACY_CLI_ENV) { | ||
| return nil | ||
| } |
There was a problem hiding this comment.
Legacy force env unwired
Low Severity
validateOutputFormatSelection skips format checks when config.GetBool(constants.SNYK_FORCE_LEGACY_CLI_ENV) is true, but this PR only adds the SNYK_FORCE_LEGACY_CLI config key constant without registering it in initApplicationConfiguration or supported env wiring. Setting the homonymous environment variable may not disable validation.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 79e329d. Configure here.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
7f3076a to
7ce6f53
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 7ce6f53. Configure here.
| displayError(tt.err, console, config, t.Context(), false) | ||
|
|
||
| expected := fmt.Sprintf("error: %s\nok: false\npath: /workspace\n", getErrorMessage(tt.err)) | ||
| assert.Equal(t, expected, stdout.String()) |
There was a problem hiding this comment.
TOON test expects extra newline
Low Severity
The TOON catalog-error test expects stdout to end with a newline after the path line, but renderTOONError formats the document without a trailing newline. That mismatch with the approved fixture test (which compares trimmed output) can fail CI or confuse consumers about the canonical TOON error shape.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 7ce6f53. Configure here.
PR Reviewer Guide 🔍
|
| @@ -0,0 +1,3 @@ | |||
| error: No supported files found | |||
| ok: false | |||
There was a problem hiding this comment.
question: does ok false or true have any meaning for an agent?
| const SNYK_OAUTH_ACCESS_TOKEN_ENV = "SNYK_OAUTH_TOKEN" | ||
| const SNYK_API_TOKEN_ENV = "SNYK_TOKEN" | ||
| const SNYK_ANALYTICS_DISABLED_ENV = "SNYK_DISABLE_ANALYTICS" | ||
| const SNYK_FORCE_LEGACY_CLI_ENV = "SNYK_FORCE_LEGACY_CLI" |
There was a problem hiding this comment.
Question: Where is this Env Var coming from.
PeterSchafer
left a comment
There was a problem hiding this comment.
I don't think this is ready yet.


Pull Request Submission Checklist
are release-note ready, emphasizing
what was changed, not how.
What does this PR do?
Adds TOON-encoded error output when
--toonis selected.Normal command errors are written to stdout using a structured document containing
error,ok, andpath. The existing JSON error behavior is preserved.The PR also makes
--toon,--json,--sarif, and--htmlmutually exclusive.Selecting more than one output format fails before command execution with
SNYK-CLI-0024. Format-selection and rendering diagnostics are written to stderrso they do not corrupt structured stdout.
The implementation does not add a TOON encoder dependency. It formats the small
error document locally, including the quoting and escaping required for TOON values.
Where should the reviewer start?
Start with
cliv2/cmd/cliv2/behavior/output.go, which contains output-formatvalidation and structured error rendering. Then review the integration in
cliv2/pkg/core/main.go.The corresponding tests are in:
cliv2/cmd/cliv2/behavior/output_test.gocliv2/pkg/core/main_test.goHow should this be manually tested?
--toon.error,ok: false, andpath.parseable on stdout.
--toonwith each of--json,--sarif, and--html.SNYK-CLI-0024, writes the diagnostic tostderr, and leaves stdout empty.
--jsonand confirm its existing structurederror output is unchanged.
What's the product update that needs to be communicated to CLI users?
CLI errors can now be rendered as TOON by passing
--toon.The
--toon,--json,--sarif, and--htmloutput options are mutuallyexclusive. Combining them returns
SNYK-CLI-0024before the command runs.Risk assessment (Medium)
This changes error formatting and stream selection for structured-output consumers.
Default human-readable output remains unchanged, and the existing JSON error shape
is preserved.
Breaking API changes
None.
What are the relevant tickets?
CLI-1828
Note
Medium Risk
Changes structured error shape/stream routing for
--toon/--jsonconsumers and adds pre-run rejection of conflicting output flags; default human output is largely unchanged.Overview
Adds TOON structured error output when
--toonis set, alongside existing JSON (error/ok/path), with local TOON quoting/escaping and no new encoder dependency.Centralizes output behavior in
behavior/output.go: rejects more than one of--toon,--json,--sarif, and--htmlbefore the command runs (including conflicts from config/env), while allowing SARIF/JSON alias pairs registered viaAddAlternativeKeys. Validation is skipped whenSNYK_FORCE_LEGACY_CLIis set.Wires this into
main.go: persistent--toonflag, pre-run validation,displayErrorusesRenderStructuredErrorand writes structured failures to stdout; human/diagnostic errors go to the stream chosen bySelectErrorOutputWriter(fixes CLI-1828 so redirects like--htmldo not mix errors into the redirected file). Data-rendering catalog errors stay on stderr even with TOON/JSON.Reviewed by Cursor Bugbot for commit 7ce6f53. Bugbot is set up for automated code reviews on this repo. Configure here.