-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: error messages are not introspectable #9383
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
Comments
The underlying error was #3514 EDIT: Updated, the error was similar to 3514.
Scenario is a go http.Client talking to a go http.Server with I will create a reduced repro case for the actual 'http: can't write HTTP request' |
@smarterclayton, elaborate. Which version of Go were you running and which error did you get? |
It looks like we should be using the same I have a patch for |
This reproduces the error as simply as I can manage: https://play.golang.org/p/eTFgX7yah5 |
Related issue #9405 was just fixed, FWIW. It is a concrete instance of this larger bug. If you want to see progress on this bug, a list of concrete examples would be best. |
@smarterclayton my interpretation of the issue that @lavalamp reported is the usage of strings and string comparison to tell what error was thrown, not the example error shown which it looks like #9405 and #3514 are about. |
Yes, I was the one who wrote the string comparison code and lavalamp was the reviewer. I was providing the example in case there was disagreement whether normal use of net/http would replicate the error such that it deserved a distinct type, which it sounds like there was not.
|
Right. If I were king, I would make these rules for library writers:
Breaking either rule makes it pretty much impossible for library consumers to correctly handle errors. |
Too late for Go 1.5. |
Closing as duplicate of #9405 (which has more detail & discussion). |
I just reviewed a PR with the line
case err.Error() == "http: can't write HTTP request on broken connection"
. That's brittle code, and it's hard to test in a way that ensures it stays in sync with any changes to the error message wording in net/http--but there's no way to improve upon it given the errors the http package emits.Possible improments:
Any mechanism is fine as long as it lets the compiler check that people are referring to the error they intend to.
(I realize this is probably low priority.)
The text was updated successfully, but these errors were encountered: