Add an Unwrap method to PathError so it works with the errors.Is/As
functions.
Change-Id: Ia6171c0418584f3cd53ee99d97c687941a9e3109
Reviewed-on: https://go-review.googlesource.com/c/go/+/168097
Reviewed-by: Damien Neil <dneil@google.com>
func (e *PathError) Error() string { return e.Op + " " + e.Path + ": " + e.Err.Error() }
+func (e *PathError) Unwrap() error { return e.Err }
+
// Timeout reports whether this error represents a timeout.
func (e *PathError) Timeout() bool {
t, ok := e.Err.(timeout)
package os_test
import (
+ "errors"
"fmt"
"io/ioutil"
"os"
t.Fatal("Open should have failed")
}
}
+
+func TestPathErrorUnwrap(t *testing.T) {
+ pe := &os.PathError{Err: os.ErrInvalid}
+ if !errors.Is(pe, os.ErrInvalid) {
+ t.Error("errors.Is failed, wanted success")
+ }
+}