Skip to content
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

Merged
merged 1 commit into from
Nov 15, 2024

Conversation

sergiu-snyk
Copy link
Contributor

@sergiu-snyk sergiu-snyk commented Nov 13, 2024

Pull Request Submission Checklist

  • Follows CONTRIBUTING guidelines
  • 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: ___)

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

Copy link
Contributor

github-actions bot commented Nov 13, 2024

Warnings
⚠️

Since the CLI is unifying on a standard and improved tooling, we're starting to migrate old-style imports and exports to ES6 ones.
A file you've modified is using either module.exports or require(). If you can, please update them to ES6 import syntax and export syntax.
Files found:

  • src/lib/snyk-test/iac-test-result.ts
⚠️

You've modified files in src/ directory, but haven't updated anything in test folder. Is there something that could be tested?

Generated by 🚫 dangerJS against 7fbae0f

@@ -58,10 +61,18 @@ const IAC_ISSUES_KEY = 'infrastructureAsCodeIssues';
export function mapIacTestResult(
iacTest: IacTestResponse,
): MappedIacTestResponse | IacTestError {
if (iacTest instanceof CustomError) {
if (iacTest instanceof Error) {
Copy link
Contributor Author

@sergiu-snyk sergiu-snyk Nov 13, 2024

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`));
}
Copy link
Contributor Author

@sergiu-snyk sergiu-snyk Nov 13, 2024

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.

@sergiu-snyk sergiu-snyk force-pushed the fix/IAC-3138/extra-debug-and-error-handling branch from 92248de to 0a25c96 Compare November 14, 2024 10:02
@sergiu-snyk sergiu-snyk force-pushed the fix/IAC-3138/extra-debug-and-error-handling branch from 0a25c96 to 7fbae0f Compare November 14, 2024 17:33
@sergiu-snyk
Copy link
Contributor Author

You've modified files in src/ directory, but haven't updated anything in test folder. Is there something that could be tested?

Adding an unit test is very difficult for this legacy code, and its value would be minimal.
We could add an acceptance test, once we determine exactly what input to feed the scanner for reproducing the issue, but first we need to get a preview build to the customer and get more data.

@sergiu-snyk sergiu-snyk marked this pull request as ready for review November 14, 2024 19:16
@sergiu-snyk sergiu-snyk requested a review from a team as a code owner November 14, 2024 19:16
@sandor-trombitas sandor-trombitas merged commit 6275f61 into main Nov 15, 2024
9 checks passed
@sandor-trombitas sandor-trombitas deleted the fix/IAC-3138/extra-debug-and-error-handling branch November 15, 2024 08:50
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.

3 participants