-
Notifications
You must be signed in to change notification settings - Fork 565
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: extra error handling and debugging [IAC-3138] #5580
fix: extra error handling and debugging [IAC-3138] #5580
Conversation
|
@@ -58,10 +61,18 @@ const IAC_ISSUES_KEY = 'infrastructureAsCodeIssues'; | |||
export function mapIacTestResult( | |||
iacTest: IacTestResponse, | |||
): MappedIacTestResponse | IacTestError { | |||
if (iacTest instanceof CustomError) { | |||
if (iacTest instanceof Error) { |
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.
This is the main fix. The customer log attached to the Jira ticket indicates that an Error
is returned in some cases from the policy engine (it should not) and, because the check was done only for CustomError
, any Error
was allowed to go on the happy path being treated as an actual result and crashing with undefined on prop checking.
This is a fix for a regression introduced here: 4d08086#diff-634d0df2f6eab15512d93b5a3ab1ada33e7146aecd9771844e6f4d503ef3f066L200
debug(`invalid scan result: ${iacTest}`); | ||
const errorMessage = iacTest.path ? `Invalid result for ${iacTest.path}` : 'Invalid result'; | ||
return mapIacTestError(new CustomError(`${errorMessage}. Please run the command again with the \`-d\` flag and contact [email protected] with the contents of the output`)); | ||
} |
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.
This condition, where a result is not set, should never happen anymore if all errors are caught by the fix above. But if it still does, we log a user friendly message instead of letting it crash trying to access props for an inexistent result.
92248de
to
0a25c96
Compare
0a25c96
to
7fbae0f
Compare
Adding an unit test is very difficult for this legacy code, and its value would be minimal. |
Pull Request Submission Checklist
What does this PR do?
Extra debug logging and potential fix for an error seen in a customer local IaC scan (no access to files):
Cannot read properties of undefined (reading 'projectType')
This customer has a particularity in the scanned repo that we cannot reproduce locally.
We intend to give the customer a CLI preview version with these fixes and gather more information on what the problem is.
See more context from the ticket and the PR inline comments.
How should this be manually tested?
Can't be tested manually, it's an error we cannot reproduce.
What are the relevant tickets?
https://snyksec.atlassian.net/browse/IAC-3138