Skip to content

net/url: (*Error).Timeout and (*Error).Temporary methods should use errors.As instead of type assertion #60578

@jens1205

Description

@jens1205

The url.Error type uses type assertion in the Timeout() and Temporary() method to delegate the work to the wrapped error:

go/src/net/url/url.go

Lines 32 to 44 in 0cd9064

func (e *Error) Timeout() bool {
t, ok := e.Err.(interface {
Timeout() bool
})
return ok && t.Timeout()
}
func (e *Error) Temporary() bool {
t, ok := e.Err.(interface {
Temporary() bool
})
return ok && t.Temporary()
}

In todays time, we shouldn't have implemented the methods like this, but should have left the task of unwrapping the error until some error in the chain implements the wanted interface to the user of the error. But as these methods now are implemented, they should use errors.As to delegate the answer to Timeout() or Temporary() to the next error in the chain who implements this interface - and not only to the direct wrapped error as it is done today.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions