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

Classify third-party upload SyntaxErrors as configuration errors #2171

Merged
merged 3 commits into from
Feb 28, 2024

Conversation

angelapwen
Copy link
Contributor

@angelapwen angelapwen commented Feb 28, 2024

We frequently see SyntaxErrors from the upload action that are currently classified as failures. We were previously catching this error in the countResultsInSarif method, but this method runs after validateSarifFileSchema, which would have thrown a SyntaxError before we're able to throw it as an InvalidRequestError.

This change moves the error catching to validateSarifFileSchema so that we will appropriately classify it as an InvalidRequestError.

Merge / deployment checklist

  • Confirm this change is backwards compatible with existing workflows.
  • Confirm the readme has been updated if necessary.
  • Confirm the changelog has been updated if necessary.

@angelapwen angelapwen requested a review from a team as a code owner February 28, 2024 15:25
henrymercer
henrymercer previously approved these changes Feb 28, 2024
Copy link
Contributor

@henrymercer henrymercer left a comment

Choose a reason for hiding this comment

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

LGTM. As a bonus, we could produce a slightly better error message, e.g. "Could not upload <path> as it is not a valid JSON file."

@angelapwen
Copy link
Contributor Author

Ah.. I think we are already attempting to catch this error, but it's not happening in the right place. Let me try to fix.

@angelapwen
Copy link
Contributor Author

Ok, I think this should do it with the appropriate error wrapping (see updated PR body)!

)}`,
);
}
} catch (e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: this now wraps quite a lot of code, for safety, consider wrapping just the JSON.parse call, or catching just SyntaxErrors.

Copy link
Contributor Author

@angelapwen angelapwen Feb 28, 2024

Choose a reason for hiding this comment

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

You're right! I changed it to wrap just the JSON.parse 😄

@angelapwen angelapwen force-pushed the classify-syntax-errors branch from 273f564 to 62712e9 Compare February 28, 2024 16:02
@angelapwen angelapwen merged commit 9330c68 into github:main Feb 28, 2024
297 checks passed
@angelapwen angelapwen deleted the classify-syntax-errors branch February 28, 2024 16:32
@github-actions github-actions bot mentioned this pull request Feb 29, 2024
8 tasks
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.

2 participants