Skip to content

fix(cli): prevent handled errors from producing duplicate output [CLI-1765] - #7130

Draft
bdemeo12 wants to merge 2 commits into
mainfrom
CLI-1765/prevent-duplicate-error-output
Draft

fix(cli): prevent handled errors from producing duplicate output [CLI-1765]#7130
bdemeo12 wants to merge 2 commits into
mainfrom
CLI-1765/prevent-duplicate-error-output

Conversation

@bdemeo12

@bdemeo12 bdemeo12 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Pull Request Submission Checklist

  • Follows CONTRIBUTING guidelines
  • Commit messages
    are release-note ready, emphasizing
    what was changed, not how.
  • Includes detailed description of changes
  • Contains risk assessment (Low | Medium | High)
  • Highlights breaking API changes (if applicable) — none
  • Links to automated tests covering new functionality
  • Includes manual testing instructions (if necessary)
  • Updates relevant GitBook documentation (PR link: ___) — n/a, no user-facing docs change
  • Includes product update to be announced in the next stable release notes

What does this PR do?

Fixes:

json output being unparseable because an extra error was printed after the result. This happens when the CLI receives an error (aside from exit status 1), it prints it — so once teardown joins the exit error together with the handled network errors, the result is no longer exit status 1 and gets printed after the real output.

Also pins snyk-docker-plugin to 9.20.0 so CI exercises the failure being fixed. (Original PR: #7047 + discussion: https://snyksec.atlassian.net/servicedesk/customer/portal/64/CLIA-1576)

Where should the reviewer start?

cliv2/pkg/core/main.goshouldSuppressDisplay and the third return value from processError, then the guarded displayError call in tearDown.

Then cliv2/pkg/core/main_test.go for the two new cases in Test_processError and the new Test_shouldSuppressDisplay.

How should this be manually tested?

Against an image whose provenance fetch fails (SDP version 9.20.0 +):

snyk container test <image> --json > out.json
jq . out.json

The container.spec.ts acceptance job is the automated equivalent — it fails on 9.20.0 without this fix, which is why the pin is included here.

What's the product update that needs to be communicated to CLI users?

n/a

…-1765]

`processError` combines the command exit error with collected network errors
via `errors.Join`, both in `FindMostRelevantError` and `createErrorWithExitCode`.
A joined error does not satisfy the direct type assertions in `displayError`,
so handled auxiliary errors were printed after valid command output - emitting
a second JSON object and breaking `JSON.parse(stdout)`.

Decide displayability at the top of `processError`, while the concrete error
type is still intact, and pass that decision through to teardown. The combined
error is still used for exit-code derivation and analytics, so both are
unchanged.

Also pins snyk-docker-plugin to 9.20.0 so CI exercises the failure this fixes:
9.20.0 performs a best-effort provenance fetch whose handled failure is what
triggered the duplicate output (see CLIA-1576).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@snyk-io

snyk-io Bot commented Aug 13, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor
Warnings
⚠️ There are multiple commits on your branch, please squash them locally before merging!
⚠️

"[fix(cli): prevent handled errors from producing duplicate output CLI-1765](#7130)" is too long. Keep the first line of your commit message under 72 characters.

⚠️

"[fix(cli): prevent handled errors from producing duplicate output CLI-1765](https://api.github.com/repos/snyk/cli/git/commits/ba58193a573fa9df9c368990c7c8ab0b48790f8f)" is too long. Keep the first line of your commit message under 72 characters.

Generated by 🚫 dangerJS against 125499b

FindMostRelevantError returns promoted errors (e.g. maintenance windows)
uncombined, so judge those on their own merits rather than on the original
error. Without this, a maintenance notice was suppressed whenever the command
also exited non-zero.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@bdemeo12

Copy link
Copy Markdown
Contributor Author

This PR originates from: #7047

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant