Skip to content

Commit

Permalink
transport: Add an Unwrap method to ConnectionError (#5148)
Browse files Browse the repository at this point in the history
  • Loading branch information
thallgren authored Feb 14, 2022
1 parent 75fd024 commit 46009ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,12 @@ func (e ConnectionError) Origin() error {
return e.err
}

// Unwrap returns the original error of this connection error or nil when the
// origin is nil.
func (e ConnectionError) Unwrap() error {
return e.err
}

var (
// ErrConnClosing indicates that the transport is closing.
ErrConnClosing = connectionErrorf(true, nil, "transport is closing")
Expand Down
8 changes: 8 additions & 0 deletions internal/transport/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"io"
"math"
"net"
"os"
"runtime"
"strconv"
"strings"
Expand Down Expand Up @@ -2404,3 +2405,10 @@ func (s) TestClientDecodeHeaderStatusErr(t *testing.T) {
})
}
}

func TestConnectionError_Unwrap(t *testing.T) {
err := connectionErrorf(false, os.ErrNotExist, "unwrap me")
if !errors.Is(err, os.ErrNotExist) {
t.Error("ConnectionError does not unwrap")
}
}

0 comments on commit 46009ac

Please sign in to comment.