-
Notifications
You must be signed in to change notification settings - Fork 916
GODRIVER-1955 create labeledError interface #651
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,7 +106,7 @@ func IsTimeout(err error) bool { | |
return ne.Timeout() | ||
} | ||
//timeout error labels | ||
if se, ok := err.(ServerError); ok { | ||
if se, ok := err.(labeledError); ok { | ||
if se.HasErrorLabel("NetworkTimeoutError") || se.HasErrorLabel("ExceededTimeLimitError") { | ||
return true | ||
} | ||
|
@@ -130,8 +130,8 @@ func unwrap(err error) error { | |
// errorHasLabel returns true if err contains the specified label | ||
func errorHasLabel(err error, label string) bool { | ||
for ; err != nil; err = unwrap(err) { | ||
if e, ok := err.(ServerError); ok { | ||
return e.HasErrorLabel(label) | ||
if e, ok := err.(labeledError); ok && e.HasErrorLabel(label) { | ||
return true | ||
} | ||
} | ||
return false | ||
|
@@ -184,14 +184,18 @@ func (e MongocryptdError) Unwrap() error { | |
return e.Wrapped | ||
} | ||
|
||
type labeledError interface { | ||
error | ||
// HasErrorLabel returns true if the error contains the specified label. | ||
HasErrorLabel(string) bool | ||
} | ||
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 seems like a reasonable change to fix this bug. To check my understanding:
Would another alternative be to have |
||
|
||
// ServerError is the interface implemented by errors returned from the server. Custom implementations of this | ||
// interface should not be used in production. | ||
type ServerError interface { | ||
error | ||
labeledError | ||
divjotarora marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// HasErrorCode returns true if the error has the specified code. | ||
HasErrorCode(int) bool | ||
// HasErrorLabel returns true if the error contains the specified label. | ||
HasErrorLabel(string) bool | ||
// HasErrorMessage returns true if the error contains the specified message. | ||
HasErrorMessage(string) bool | ||
// HasErrorCodeWithMessage returns true if any of the contained errors have the specified code and message. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.