Skip to content

net/url: url.Error should propagate the net.Error interface #12866

Closed
@jum

Description

@jum

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

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions