-
Notifications
You must be signed in to change notification settings - Fork 578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: ensure nested legacycli invocations forward errors #5709
base: main
Are you sure you want to change the base?
fix: ensure nested legacycli invocations forward errors #5709
Conversation
|
c4f87b9
to
c24b51e
Compare
@@ -1,7 +1,9 @@ | |||
const stripAnsi = require('strip-ansi'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: Use imports here rather than commonjs require format.
src/cli/ipc.ts
Outdated
err.metadata.status = 0; | ||
} | ||
|
||
const data = (err as ProblemError) | ||
.toJsonApi('error-catalog-ipc-instance?') | ||
.toJsonApi('error-catalog-ipc-instance') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Why remove the ?
character from this string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added that in the previous PR when I was reading about the instance parameter (and I was confused about what it did), and I missed removing that 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove that as part of this change?
|
||
// NOTE: Only set if the invocation uses the --json flag. There's no need for output suppression if the invocation does NOT use StdIO | ||
// (meaning the TS CLI is handling the user output directly), so we can disable the suppression in order to surface this errors properly. | ||
useStdIO := c.globalConfig.GetBool(configuration.WORKFLOW_USE_STDIO) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: The comment here mentions: Only set if the invocation uses the --json flag. But below it looks like we are checking, configuration.WORKFLOW_USE_STDIO
, how does that relate to the --json flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was referring to the "suppressJsonOutput" field being set, will update this to be a bit more expressive about that.
@@ -539,6 +562,9 @@ func MainWithErrorCode() (int, []error) { | |||
outputWorkflow, _ := globalEngine.GetWorkflow(localworkflows.WORKFLOWID_OUTPUT_WORKFLOW) | |||
outputFlags := workflow.FlagsetFromConfigurationOptions(outputWorkflow.GetConfigurationOptions()) | |||
rootCommand.PersistentFlags().AddFlagSet(outputFlags) | |||
// add output flags as persistent flags | |||
_ = rootCommand.ParseFlags(os.Args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: What is the incorrect behaviour you were seeing which required this change? I am not sure I understand how it is related to the change you are looking to make here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The configuration values were not being populated properly (eg: even if the --json flag was in the args, the configuration flag for the JSON output would have the default value of false).
This would result in incorrect output for errors sent thought IPC: we would get the normal human readable output even if JSON formatted output was expected.
c24b51e
to
f48415e
Compare
Pull Request Submission Checklist
What does this PR do?
Following the work from CLI-646 that added the capability of capturing errors from TS CLI invocations, this adds PR aims to ensure nested invocations of the TS CLI are forwarded properly to debug logs, analytics and output.
One current gap left from CLI-646 is the fact that if the
--sarif
or--json
flags are set, we don't send this errors to the IPC. We can retrieve error messages from the JSON payload, but in the case of SARIF, there is no error message present.Extracting the error message from the JSON payload is just about parsing and accessing the "error" field. I added a fallback case and in case parsing fails, we default back to the normal Error.message field.
Here's an example of an error caught when the
--json
flag is set:Where should the reviewer start?
--json
flag is set, this will add a meta field "suppressJsonOutput" to the error in order to signal the Golang CLI to now show this error. Other things added was just around extracting the error message from the stringified JSON payload from the messsage field of the caught error.suppressJsonOutput
field.How should this be manually tested?
Using the
snyk-macos-arm64 sbom --format cyclonedx1.4+json --file=./foldernotthere
command, the expected error message would surface the fact that the specified file is not present, instead of the "An error occurred while running the underlying analysis needed to generate the SBOM." message. Other commands that make use of TS CLI workflow invocations should also surface the errors captured though the IPC.Related