-
Notifications
You must be signed in to change notification settings - Fork 919
GODRIVER-3690 Add ErrorCodesFrom to the mongo package #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?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -364,10 +364,12 @@ func hasErrorCode(srvErr ServerError, code int) bool { | |
| return false | ||
| } | ||
|
|
||
| var _ ServerError = CommandError{} | ||
| var _ ServerError = WriteError{} | ||
| var _ ServerError = WriteException{} | ||
| var _ ServerError = BulkWriteException{} | ||
| var ( | ||
| _ ServerError = CommandError{} | ||
| _ ServerError = WriteError{} | ||
| _ ServerError = WriteException{} | ||
| _ ServerError = BulkWriteException{} | ||
| ) | ||
|
|
||
| var _ error = ClientBulkWriteException{} | ||
|
|
||
|
|
@@ -901,3 +903,17 @@ func joinBatchErrors(errs []error) string { | |
|
|
||
| return buf.String() | ||
| } | ||
|
|
||
| // ErrorCodesFrom returns the list of server error codes contained in err. | ||
| func ErrorCodesFrom(err error) []int { | ||
| if err == nil { | ||
| return nil | ||
| } | ||
|
|
||
| var ec interface{ ErrorCodes() []int } | ||
| if errors.As(wrapErrors(err), &ec) { | ||
| return ec.ErrorCodes() | ||
|
Comment on lines
+913
to
+915
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can users use E.g. var se mongo.ServerError
if errors.As(err, &se) {
se.ErrorCodes()
}
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would only work if |
||
| } | ||
|
|
||
| return []int{} | ||
| } | ||
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.
Optional: Consider naming this
ErrorCodes, which matches the method name on the error types.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.
Good idea 👍