-
Notifications
You must be signed in to change notification settings - Fork 356
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
feat: further error re-classification #2833
Conversation
…tatus report is produced
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.
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
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)) | ||
); |
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.
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.
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 |
src/api-client.ts
Outdated
e.message.includes("Bad credentials") || | ||
e.message.includes("Not Found") || | ||
e.message.includes("Resource not accessible by integration") || |
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.
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.
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.
Thanks for the suggestion, I have implemented this at 55ee663.
src/status-report.ts
Outdated
return error instanceof ConfigurationError ? "user-error" : "failure"; | ||
if ( | ||
error instanceof ConfigurationError || | ||
error instanceof InvalidSarifUploadError |
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 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
.
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 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.
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'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 InvalidSarifUploadError
s 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 InvalidSarifUploadError
s that aren't user errors.
If we're seeing InvalidSarifUploadError
s 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 ConfigurationError
s.
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.
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
src/upload-lib.ts
Outdated
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") || |
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.
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?
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.
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.
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.
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
src/resolve-environment-action.ts
Outdated
const isThirdPartyAnalysis = !isFirstPartyAnalysis( | ||
ActionName.ResolveEnvironment, | ||
); |
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 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.
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.
(posting this review so Slack doesn't keep reminding me)
See #2833 (comment)
…as ConfigurationError if in known error category
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.
Thanks for addressing the feedback! Looks good, just one suggestion.
src/upload-sarif-action.ts
Outdated
// There was a problem validating the JSON (SARIF) file. | ||
unwrappedError instanceof SyntaxError; |
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.
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.
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.
Thanks, this is a great suggestion! Added in 676a422
Description
This PR adds some further error classification for issues we observe in telemetry, along with a re-classification of
InvalidSarifUploadError
s asuser-error
s.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.