Skip to content

Conversation

@snyk-tim
Copy link
Contributor

@snyk-tim snyk-tim commented Jan 6, 2026

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)
  • Links to automated tests covering new functionality
  • Includes manual testing instructions (if necessary)
  • Updates relevant GitBook documentation (PR link: ___)
  • Includes product update to be announced in the next stable release notes

What does this PR do?

Currently, --print-effective-graph only outputs results for successfully handled project files detected during analysis, and excludes projects that encounter errors during detection. This PR introduces --print-effective-graph-with-errors, which includes those errors in the output.

The core behaviour remains unchanged, and the command continues to emit one line per project file found, whether processing succeeds or results in an error.

This change is required to surface errors to customers using the new Test flow.

Error JSON lines will not include the depGraph field and instead include an error field, shaped as an error catalog error in the JSON API format. Error lines will also omit the target field, which is not required in this context.

Error Catalog Integration

The new getOrCreateErrorCatalogError() helper function will take any Error type and return a ProblemError:

  • If the underlying error is already a ProblemError, it is returned as is.
  • If the error is a CustomError with an attached errorCatalog, that catalog error is used.
  • Otherwise, the error message is wrapped in a GeneralCLIFailureError to return the error message as a general CLI ProblemError.

Why not add the errors to --print-effective-graph?

Several extensions rely on the output produced by the --print-effective-graph argument in this project. The cli-extension-dep-graph extension, in particular, consumes this output and is itself depended on by a number of other extensions. Including errors by default would require all downstream extensions to handle additional workflow.Data objects created to represent those errors, and they would likely fail without corresponding updates. For this reason, exposing errors as an opt-in option is the safer and less disruptive approach.

Where should the reviewer start?

The main change is in src/lib/snyk-test/run-test.ts, where error JSON lines are emitted when failedResults are present and the --print-effective-graph-with-errors argument is supplied.

How should this be manually tested?

Run the following command on an example project which is broken somehow.

snyk test --all-projects --print-effective-graph-with-errors

Compare the output to the current argument.

snyk test --all-projects --print-effective-graph

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

This is used internally by other CLI extensions, primarily cli-extension-dep-graph.

@snyk-tim snyk-tim force-pushed the feat/output-errors-in-json branch from 3d22f2e to 7a349a2 Compare January 7, 2026 10:06
Comment on lines +173 to +178
!!opts['print-effective-graph'] ||
shouldPrintEffectiveDepGraphWithErrors(opts)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The shouldPrintEffectiveDepGraph() check is used in multiple places and should remain true for both --print-effective-graph and --print-effective-graph-with-errors

@snyk-tim snyk-tim marked this pull request as ready for review January 7, 2026 11:40
@snyk-tim snyk-tim requested review from a team as code owners January 7, 2026 11:40
@snyk-tim snyk-tim changed the title feat: add option to output errors in json for test [UNIFY-1102] feat: include errors for projects when printing JSON graph [UNIFY-1102] Jan 7, 2026
@snyk-tim snyk-tim force-pushed the feat/output-errors-in-json branch 2 times, most recently from 2bd4eb2 to e7ed96e Compare January 8, 2026 09:58
return new Promise((res, rej) => {
const effectiveGraphErrorOutput = {
error: {
id: 'SNYK-CLI-0000',
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Is there a reason why we do always use this generic error code? Why don't we try to use additional information from the original error instance we received from the plugins. Choosing this hardcoded value here will make it more and more difficult to correctly report on errors in the future. It would even be better if the string would be empty by default, so that the decision of mapping it to generic can be done somewhere else.

I hope this makes sense. If you want we can chat a bit more. Maybe look at the CustomError on how we made it possible to transparently handle error catalog errors if available.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated this so that the error returned will always return a ProblemError.

  • If the underlying error is already a ProblemError, it is returned as is.
  • If the error is a CustomError with an attached errorCatalog, that catalog error is used.
  • Otherwise, the error message is wrapped in a GeneralCLIFailureError to return the error message as a general CLI ProblemError.

@snyk-tim snyk-tim force-pushed the feat/output-errors-in-json branch 4 times, most recently from 29511d8 to 2165662 Compare January 20, 2026 12:26

// Should succeed (exit code 0) because at least one project succeeded
// Or exit code 2 if the error propagates
expect([0, 2]).toContain(code);
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Are we really uncertain about the expected exit code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the test we should expect 0. I've fixed this 🙏

@snyk-tim snyk-tim force-pushed the feat/output-errors-in-json branch from 2165662 to 365cda2 Compare January 20, 2026 12:28
@snyk-tim snyk-tim force-pushed the feat/output-errors-in-json branch from 365cda2 to 6c6a11d Compare January 20, 2026 12:31
Copy link
Contributor

@PeterSchafer PeterSchafer left a comment

Choose a reason for hiding this comment

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

Nice! Thank you!

@snyk-tim snyk-tim merged commit 7bc5f76 into main Jan 20, 2026
6 checks passed
@snyk-tim snyk-tim deleted the feat/output-errors-in-json branch January 20, 2026 13:56
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.

4 participants