-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Try to stdlib errors.Unwrap errors as well #1660
Closed
Closed
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e760fac
Try to stdlib errors.Unwrap errors as well
mstoykov c26e54e
Add test for connReset errorCode and a fix
mstoykov d1def0f
Add test for the Unwrap error codes path
mstoykov 36837c1
Try to fix test on windows
mstoykov 19fe91d
Update github.com/pkg/errors to v0.9.1
mstoykov 9fda18e
Drop the usage of pkg/errors in error codes
mstoykov 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 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// +build !windows | ||
|
||
package httpext | ||
|
||
import ( | ||
"net" | ||
"os" | ||
) | ||
|
||
func getOSSyscallErrorCode(e *net.OpError, se *os.SyscallError) (errCode, string) { | ||
return 0, "" | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package httpext | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"os" | ||
"syscall" | ||
) | ||
|
||
func getOSSyscallErrorCode(e *net.OpError, se *os.SyscallError) (errCode, string) { | ||
switch se.Unwrap() { | ||
case syscall.WSAECONNRESET: | ||
return tcpResetByPeerErrorCode, fmt.Sprintf(tcpResetByPeerErrorCodeMsg, e.Op) | ||
} | ||
return 0, "" | ||
} |
This file contains 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.
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 am confused - wouldn't this have been unwrapped in the call above? After all,
net.OpError
hasUnwrap()
. Maybe that automaticUnwrap()
above should only happen in thedefault:
case of this bigswitch
?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.
Here we have syscall.ECONNRESET inside os.SyscallError inside net.OpError maybe inside something else.
I think that for this chain specifically everything implements Unwrap now ... but it didn't when this code was added IIRC. I really don't want to put syscall.ECONNRESET in the top switch because:
Moving the Unwrap to the default seems like a not bad idea ... should we also move the Cause then ?
I am not really certain what wraps what and where and whether us moving things around will not break something as ... well most of the tests for this are syntethic - I created a specific wrappings of errors that than goes through this code, but as evident by the fact it hasn't caught some errors ... my matroshkas aren't what is genereated in the actual code of the application. So I do prefer to change this less ... if possible :D
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.
Moving Unwrap breaks the
TestDNsErrorTestDnsResolve as it DNSError inside OpError ... maybe I should just move DNSError under OpError 🤔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.
Yes, this is what I meant, and it is going to make the change more minimal
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.
Unwrap in the begining is the same logic as Cause ... just slower and with a return path:
Cause basically says get me the inner error of my Cause error that doesn't implement the causer interface.
What happens with the Unwrap above is that we Unwrap (and Cause) until we get to an error that no longer implements neither on (or just doesn't have inner error) and than we check it, if it is a concrete error - we return that and if not we go one level above and try that error
Looking at the document Unwrap was added in a later version to github.com/pkg/errors adn arguably if we upgrade the version we can drop the errors.Cause 🤔