Closed
Description
At some points in a program it might interesting to find out if a network error is transient or a timeout. If the program uses Dial et. al. this is handled by calling the Temporary() or Timeout() interfaces on net.Error. But if the program uses http.Get or similar, the net.Error is hidden behind url.Error.Err. one has to use a logic like this check for transient errors:
testErr := err
if e, ok := testErr.(*url.Error); ok {
testErr = e.Err
}
// As we are called regularly by cron, ignore some errors.
type timeout interface {
Timeout() bool
}
if e, ok := testErr.(timeout); ok {
if e.Timeout() {
err = nil
}
}
type temporary interface {
Temporary() bool
}
if e, ok := testErr.(temporary); ok {
if e.Temporary() {
err = nil
}
}
If url.Error would embed Err anonymously, any interfaces would be available without the type assertion to *url.Error.
Metadata
Metadata
Assignees
Type
Projects
Relationships
Development
No branches or pull requests
Activity
[-]url.Error should propagate the net.Error interface[/-][+]net/url: url.Error should propagate the net.Error interface[/+]rakyll commentedon Oct 7, 2015
/cc @bradfitz
bradfitz commentedon Oct 8, 2015
Sure. If somebody wants to send a CL to make
url.Error
implementnet.Error
, that's fine with me at least.davecheney commentedon Oct 8, 2015
I'll take a shot
davecheney commentedon Oct 10, 2015
@jum I started to look into this, and I cannot find a place where url.Error.Err is assigned something that conforms to net.Error. I think there is nothing to do on this ticket because url.Error never wraps a net.Error.
Can you please provide some sample code that shows a url.Error holding a net.Error.
Thanks
Dave
davecheney commentedon Oct 10, 2015
@jum sorry, I found it. There is one place in http/client.go, https://github.com/golang/go/blob/master/src/net/http/client.go#L417, where url.Error is used to record the url that failed in a redirect chain.
davecheney commentedon Oct 10, 2015
https://go-review.googlesource.com/15672
gopherbot commentedon Oct 10, 2015
CL https://golang.org/cl/15672 mentions this issue.
arvenil commentedon Feb 23, 2016
I just wasted way more than 15 minutes trying to figure out why some network error was not catch by
err.(net.Error)
even though docs stated it should. Turned outurl.Error
implementsnet.Error
since go 1.6.I wonder if anyone thought/propose adding go version numbers to docs saying from which version given method is available?
bradfitz commentedon Feb 23, 2016
@arvenil, there is a separate bug open for that. I don't know its number off hand, though.
arvenil commentedon Feb 23, 2016
@bradfitz I didn't found it before posting, but I've tried again now and I think it is this one #5778 ? Thank you!