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

feat: further error re-classification #2833

Merged
merged 11 commits into from
Apr 2, 2025

Conversation

NlightNFotis
Copy link
Member

Description

This PR adds some further error classification for issues we observe in telemetry, along with a re-classification of InvalidSarifUploadErrors as user-errors.

Merge / deployment checklist

NOTE: This is an internal/telemetry change, and doesn't affect users in any way that would induce the need to update either the readme or the changelog file.

  • 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.

@Copilot Copilot bot review requested due to automatic review settings March 31, 2025 11:24
@NlightNFotis NlightNFotis requested a review from a team as a code owner March 31, 2025 11:24
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refines how error classification is handled in telemetry by re-classifying InvalidSarifUploadError as a user error and improving error message matching for configuration and upload errors. Key changes include:

  • Updating error classification functions (shouldConsiderConfigurationError and shouldConsiderInvalidRequest) to use substring matching.
  • Modifying the getActionsStatus logic to treat InvalidSarifUploadError as a user-error.
  • Extending API client error handling to cover additional error message conditions.

Reviewed Changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/upload-lib.ts Updated error classification logic and exported the helper functions.
src/upload-lib.test.ts Added tests validating new error classification behavior for configuration and invalid request errors.
src/status-report.ts & lib/status-report.js Modified getActionsStatus to include InvalidSarifUploadError handling.
src/api-client.ts & lib/api-client.js Extended error message matching in wrapApiConfigurationError.
Other test files Added corresponding unit tests verifying updated error handling.

Tip: Copilot code review supports C#, Go, Java, JavaScript, Markdown, Python, Ruby and TypeScript, with more languages coming soon. Learn more

Comment on lines +740 to 748
const expectedConfigErrors = [
"CodeQL analyses from advanced configurations cannot be processed when the default setup is enabled",
"rejecting delivery as the repository has too many logical alerts",
];

return (
processingErrors.length === 1 &&
processingErrors[0] ===
"CodeQL analyses from advanced configurations cannot be processed when the default setup is enabled"
expectedConfigErrors.some((msg) => processingErrors[0].includes(msg))
);
Copy link
Preview

Copilot AI Mar 31, 2025

Choose a reason for hiding this comment

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

Using .includes for matching error messages can potentially lead to false positives if an error string contains an expected substring unintentionally. Consider using stricter matching or regex patterns to ensure only the intended error messages are classified.

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

@NlightNFotis
Copy link
Member Author

Hi @henrymercer, would it be possible to get a review on this one?

I'd like some further eyes on f21cf0b, as I'm fairly confident the functionality works, but I'm not sure if we are to consider InvalidSarifUploadErrors as user-errors (I've seen discussions leaning both ways).

Comment on lines 248 to 250
e.message.includes("Bad credentials") ||
e.message.includes("Not Found") ||
e.message.includes("Resource not accessible by integration") ||
Copy link
Contributor

Choose a reason for hiding this comment

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

There's an opportunity to provide a better error message here too, for example for bad credentials / not found we could ask whether the job has contents: read and security-events: write permissions.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the suggestion, I have implemented this at 55ee663.

return error instanceof ConfigurationError ? "user-error" : "failure";
if (
error instanceof ConfigurationError ||
error instanceof InvalidSarifUploadError
Copy link
Contributor

Choose a reason for hiding this comment

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

This should only be a user error if a third-party tool generated the SARIF. See the handling of InvalidSarifUploadError in src/upload-sarif-action.ts.

Copy link
Member Author

Choose a reason for hiding this comment

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

I put some thought into trying to come up with a schema for identifying how to handle this case, and I came to realisation that perhaps the best way to implement this is by passing getActionsStatus an extra parameter indicating whether the analysis is a third party one or not. This would also make it easier to extend it in the future based on this information.

I have implemented this approach in 55ee663.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer to keep getActionsStatus simple and delegate the task of deciding whether errors are user errors or not to the part of the code where the relevant logic is implemented.

For example, the upload-sarif Action we should catch any InvalidSarifUploadErrors and rethrow them as a ConfigurationError if it's a third-party run. So by the time we reach the top-level status reporting logic, we should only be dealing with InvalidSarifUploadErrors that aren't user errors.

If we're seeing InvalidSarifUploadErrors from third-party runs, there's a bug in the upload-sarif Action — we should fix that to make sure it's wrapping those errors in ConfigurationErrors.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you, I have re-implemented it this way, managing to repurpose some of the code already written to simplify the code and its handling: 498c7f3

return processingErrors.every(
(error) =>
error.startsWith("rejecting SARIF") ||
error.startsWith("an invalid URI was provided as a SARIF location") ||
error.startsWith("locationFromSarifResult: expected artifact location") ||
error.startsWith("SyntaxError: Unexpected end of JSON input") ||
Copy link
Contributor

Choose a reason for hiding this comment

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

How's this possible if we're validating the SARIF against the JSON schema before we try to upload it? I'd be surprised if this was going wrong, but is there a bug in the way we combine the SARIF files?

Copy link
Contributor

Choose a reason for hiding this comment

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

Are we getting this error when we're doing the validation locally? And if so, does this function catch the error?

If we're getting this error from the server, I would say this is a bug.

Copy link
Member Author

Choose a reason for hiding this comment

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

Henry is correct, I misunderstood the error location and thought this was coming from the backend. Judging from the stack trace I've seen, this appears to be coming from the uploadFiles function calling validateSarifFileSchema on each input file, which then fails the validation.

In this case, the upload-sarif-action.ts would be the best location for that, and we also probably want to categorise as a user-error the case where we ourselves are not the producers of a SARIF file with syntax errors.

I have now corrected this at b53826d

@NlightNFotis NlightNFotis requested a review from henrymercer April 1, 2025 14:15
Comment on lines 86 to 88
const isThirdPartyAnalysis = !isFirstPartyAnalysis(
ActionName.ResolveEnvironment,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you convert this to a function in status-report.ts? You are duplicating and negating the call to isFirstPartyAnalysis in enough places that it might be cleaner to just extract it to a separate function.

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.

(posting this review so Slack doesn't keep reminding me)

See #2833 (comment)

@NlightNFotis NlightNFotis requested a review from henrymercer April 2, 2025 14:23
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.

Thanks for addressing the feedback! Looks good, just one suggestion.

Comment on lines 112 to 113
// There was a problem validating the JSON (SARIF) file.
unwrappedError instanceof SyntaxError;
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a small chance that by catching any SyntaxError here we miss something genuine. If we put a try/catch around the JSON parse block specifically, and throw an InvalidSarifUploadError if there was invalid JSON, we can avoid that situation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, this is a great suggestion! Added in 676a422

@NlightNFotis NlightNFotis merged commit e13fe0d into main Apr 2, 2025
270 checks passed
@NlightNFotis NlightNFotis deleted the NlightNFotis/reclassify_upload_sarif_issues branch April 2, 2025 19:09
@github-actions github-actions bot mentioned this pull request Apr 7, 2025
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.

3 participants