Skip to content

Commit 46009ac

Browse files
authored
transport: Add an Unwrap method to ConnectionError (#5148)
1 parent 75fd024 commit 46009ac

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

internal/transport/transport.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,12 @@ func (e ConnectionError) Origin() error {
741741
return e.err
742742
}
743743

744+
// Unwrap returns the original error of this connection error or nil when the
745+
// origin is nil.
746+
func (e ConnectionError) Unwrap() error {
747+
return e.err
748+
}
749+
744750
var (
745751
// ErrConnClosing indicates that the transport is closing.
746752
ErrConnClosing = connectionErrorf(true, nil, "transport is closing")

internal/transport/transport_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"io"
2828
"math"
2929
"net"
30+
"os"
3031
"runtime"
3132
"strconv"
3233
"strings"
@@ -2404,3 +2405,10 @@ func (s) TestClientDecodeHeaderStatusErr(t *testing.T) {
24042405
})
24052406
}
24062407
}
2408+
2409+
func TestConnectionError_Unwrap(t *testing.T) {
2410+
err := connectionErrorf(false, os.ErrNotExist, "unwrap me")
2411+
if !errors.Is(err, os.ErrNotExist) {
2412+
t.Error("ConnectionError does not unwrap")
2413+
}
2414+
}

0 commit comments

Comments
 (0)