diff options
Diffstat (limited to 'src/errors')
-rw-r--r-- | src/errors/errors.go | 12 | ||||
-rw-r--r-- | src/errors/wrap.go | 4 | ||||
-rw-r--r-- | src/errors/wrap_test.go | 11 |
3 files changed, 14 insertions, 13 deletions
diff --git a/src/errors/errors.go b/src/errors/errors.go index d923ad4b70..f2fabacd4e 100644 --- a/src/errors/errors.go +++ b/src/errors/errors.go @@ -27,30 +27,30 @@ // second. It reports whether it finds a match. It should be used in preference to // simple equality checks: // -// if errors.Is(err, os.ErrExist) +// if errors.Is(err, fs.ErrExist) // // is preferable to // -// if err == os.ErrExist +// if err == fs.ErrExist // -// because the former will succeed if err wraps os.ErrExist. +// because the former will succeed if err wraps fs.ErrExist. // // As unwraps its first argument sequentially looking for an error that can be // assigned to its second argument, which must be a pointer. If it succeeds, it // performs the assignment and returns true. Otherwise, it returns false. The form // -// var perr *os.PathError +// var perr *fs.PathError // if errors.As(err, &perr) { // fmt.Println(perr.Path) // } // // is preferable to // -// if perr, ok := err.(*os.PathError); ok { +// if perr, ok := err.(*fs.PathError); ok { // fmt.Println(perr.Path) // } // -// because the former will succeed if err wraps an *os.PathError. +// because the former will succeed if err wraps an *fs.PathError. package errors // New returns an error that formats as the given text. diff --git a/src/errors/wrap.go b/src/errors/wrap.go index b82ca34b46..7928fe673e 100644 --- a/src/errors/wrap.go +++ b/src/errors/wrap.go @@ -32,9 +32,9 @@ func Unwrap(err error) error { // An error type might provide an Is method so it can be treated as equivalent // to an existing error. For example, if MyError defines // -// func (m MyError) Is(target error) bool { return target == os.ErrExist } +// func (m MyError) Is(target error) bool { return target == fs.ErrExist } // -// then Is(MyError{}, os.ErrExist) returns true. See syscall.Errno.Is for +// then Is(MyError{}, fs.ErrExist) returns true. See syscall.Errno.Is for // an example in the standard library. func Is(err, target error) bool { if target == nil { diff --git a/src/errors/wrap_test.go b/src/errors/wrap_test.go index 4a4a732c9b..6f66e99c4a 100644 --- a/src/errors/wrap_test.go +++ b/src/errors/wrap_test.go @@ -7,6 +7,7 @@ package errors_test import ( "errors" "fmt" + "io/fs" "os" "reflect" "testing" @@ -61,7 +62,7 @@ type poser struct { f func(error) bool } -var poserPathErr = &os.PathError{Op: "poser"} +var poserPathErr = &fs.PathError{Op: "poser"} func (p *poser) Error() string { return p.msg } func (p *poser) Is(err error) bool { return p.f(err) } @@ -71,7 +72,7 @@ func (p *poser) As(err interface{}) bool { *x = p case *errorT: *x = errorT{"poser"} - case **os.PathError: + case **fs.PathError: *x = poserPathErr default: return false @@ -81,7 +82,7 @@ func (p *poser) As(err interface{}) bool { func TestAs(t *testing.T) { var errT errorT - var errP *os.PathError + var errP *fs.PathError var timeout interface{ Timeout() bool } var p *poser _, errF := os.Open("non-existing") @@ -240,7 +241,7 @@ func (errorUncomparable) Is(target error) bool { func ExampleIs() { if _, err := os.Open("non-existing"); err != nil { - if errors.Is(err, os.ErrNotExist) { + if errors.Is(err, fs.ErrNotExist) { fmt.Println("file does not exist") } else { fmt.Println(err) @@ -253,7 +254,7 @@ func ExampleIs() { func ExampleAs() { if _, err := os.Open("non-existing"); err != nil { - var pathError *os.PathError + var pathError *fs.PathError if errors.As(err, &pathError) { fmt.Println("Failed at path:", pathError.Path) } else { |