-
Notifications
You must be signed in to change notification settings - Fork 918
(POC) GODRIVER-3690 Extend CommandFailedEvent with error codes #2241
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
base: master
Are you sure you want to change the base?
(POC) GODRIVER-3690 Extend CommandFailedEvent with error codes #2241
Conversation
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 extends the CommandFailedEvent structure to include error codes, addressing GODRIVER-3690. The change enables users to access error codes directly from command failure events without parsing the error themselves.
Key changes:
- Added a
Codesfield toCommandFailedEventto expose error codes - Implemented
errorCodes()helper function to extract codes from driver errors - Added test coverage for the new field
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| event/monitoring.go | Added Codes field to CommandFailedEvent structure |
| x/mongo/driver/operation.go | Populates the new Codes field when publishing failed events; removed blank line |
| x/mongo/driver/errors.go | Implemented errorCodes() function to extract error codes from driver errors |
| mongo/errors.go | Refactored variable declarations to use var() block (style change) |
| internal/integration/clam_prose_test.go | Added test case for CommandFailedEvent.Codes; removed blank line |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if driversErr, ok := err.(Error); ok { | ||
| return []int32{driversErr.Code} | ||
| } | ||
|
|
Copilot
AI
Nov 18, 2025
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.
Type assertion should use the modern syntax with type parameter. Change err.(Error) to use a type switch or keep the current form but consider that direct type assertion without pointer check may not catch *Error types. Verify if both Error and *Error need to be handled.
| if driversErr, ok := err.(Error); ok { | |
| return []int32{driversErr.Code} | |
| } | |
| switch e := err.(type) { | |
| case Error: | |
| return []int32{e.Code} | |
| case *Error: | |
| if e != nil { | |
| return []int32{e.Code} | |
| } | |
| } |
🧪 Performance ResultsCommit SHA: 86d0004The following benchmark tests for version 691bc82b7c8b8a000704f85a had statistically significant changes (i.e., |z-score| > 1.96):
For a comprehensive view of all microbenchmark results for this PR's commit, please check out the Evergreen perf task for this patch. |
API Change Report./v2/eventincompatible changesCommandFailedEvent: old is comparable, new is not compatible changesCommandFailedEvent.Codes: added |
GODRIVER-3690