transport: Add an Unwrap method to ConnectionError (#5148)

This commit is contained in:
Thomas Hallgren 2022-02-14 16:44:21 +01:00 committed by GitHub
parent 75fd0240ac
commit 46009ac902
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -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")

View File

@ -27,6 +27,7 @@ import (
"io"
"math"
"net"
"os"
"runtime"
"strconv"
"strings"
@ -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")
}
}