diff options
| author | Katie Hockman <katie@golang.org> | 2020-12-14 10:03:05 -0500 |
|---|---|---|
| committer | Katie Hockman <katie@golang.org> | 2020-12-14 10:06:13 -0500 |
| commit | 0345ede87ee12698988973884cfc0fd3d499dffd (patch) | |
| tree | 7123cff141ee5661208d2f5f437b8f5252ac7f6a /src/os/error.go | |
| parent | 4651d6b267818b0e0d128a5443289717c4bb8cbc (diff) | |
| parent | 0a02371b0576964e81c3b40d328db9a3ef3b031b (diff) | |
| download | go-0345ede87ee12698988973884cfc0fd3d499dffd.tar.xz | |
[dev.fuzz] all: merge master into dev.fuzz
Change-Id: I5d8c8329ccc9d747bd81ade6b1cb7cb8ae2e94b2
Diffstat (limited to 'src/os/error.go')
| -rw-r--r-- | src/os/error.go | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/src/os/error.go b/src/os/error.go index 875cc9711f..704a6fb29e 100644 --- a/src/os/error.go +++ b/src/os/error.go @@ -7,6 +7,7 @@ package os import ( "internal/oserror" "internal/poll" + "io/fs" ) // Portable analogs of some common system call errors. @@ -16,20 +17,17 @@ import ( var ( // ErrInvalid indicates an invalid argument. // Methods on File will return this error when the receiver is nil. - ErrInvalid = errInvalid() // "invalid argument" + ErrInvalid = fs.ErrInvalid // "invalid argument" + + ErrPermission = fs.ErrPermission // "permission denied" + ErrExist = fs.ErrExist // "file already exists" + ErrNotExist = fs.ErrNotExist // "file does not exist" + ErrClosed = fs.ErrClosed // "file already closed" - ErrPermission = errPermission() // "permission denied" - ErrExist = errExist() // "file already exists" - ErrNotExist = errNotExist() // "file does not exist" - ErrClosed = errClosed() // "file already closed" ErrNoDeadline = errNoDeadline() // "file type does not support deadline" ErrDeadlineExceeded = errDeadlineExceeded() // "i/o timeout" ) -func errInvalid() error { return oserror.ErrInvalid } -func errPermission() error { return oserror.ErrPermission } -func errExist() error { return oserror.ErrExist } -func errNotExist() error { return oserror.ErrNotExist } func errClosed() error { return oserror.ErrClosed } func errNoDeadline() error { return poll.ErrNoDeadline } @@ -47,21 +45,7 @@ type timeout interface { } // PathError records an error and the operation and file path that caused it. -type PathError struct { - Op string - Path string - Err error -} - -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) - return ok && t.Timeout() -} +type PathError = fs.PathError // SyscallError records an error from a specific system call. type SyscallError struct { @@ -92,6 +76,9 @@ func NewSyscallError(syscall string, err error) error { // IsExist returns a boolean indicating whether the error is known to report // that a file or directory already exists. It is satisfied by ErrExist as // well as some syscall errors. +// +// This function predates errors.Is. It only supports errors returned by +// the os package. New code should use errors.Is(err, os.ErrExist). func IsExist(err error) bool { return underlyingErrorIs(err, ErrExist) } @@ -99,6 +86,9 @@ func IsExist(err error) bool { // IsNotExist returns a boolean indicating whether the error is known to // report that a file or directory does not exist. It is satisfied by // ErrNotExist as well as some syscall errors. +// +// This function predates errors.Is. It only supports errors returned by +// the os package. New code should use errors.Is(err, os.ErrNotExist). func IsNotExist(err error) bool { return underlyingErrorIs(err, ErrNotExist) } @@ -106,12 +96,21 @@ func IsNotExist(err error) bool { // IsPermission returns a boolean indicating whether the error is known to // report that permission is denied. It is satisfied by ErrPermission as well // as some syscall errors. +// +// This function predates errors.Is. It only supports errors returned by +// the os package. New code should use errors.Is(err, os.ErrPermission). func IsPermission(err error) bool { return underlyingErrorIs(err, ErrPermission) } // IsTimeout returns a boolean indicating whether the error is known // to report that a timeout occurred. +// +// This function predates errors.Is, and the notion of whether an +// error indicates a timeout can be ambiguous. For example, the Unix +// error EWOULDBLOCK sometimes indicates a timeout and sometimes does not. +// New code should use errors.Is with a value appropriate to the call +// returning the error, such as os.ErrDeadlineExceeded. func IsTimeout(err error) bool { terr, ok := underlyingError(err).(timeout) return ok && terr.Timeout() |
