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 differs from os.IsNotExist() in that it can identify an error through wrapping layers.
(err error)
| 88 | // This function differs from os.IsNotExist() in that it |
| 89 | // can identify an error through wrapping layers. |
| 90 | func IsNotExist(err error) bool { |
| 91 | // errors.Is() is not able to peek through os.SyscallError, |
| 92 | // whereas os.IsNotExist() can. Conversely, os.IsNotExist() |
| 93 | // cannot peek through Unwrap, whereas errors.Is() can. So we |
| 94 | // need to try both. |
| 95 | if errors.Is(err, ErrNotExist) || os.IsNotExist(errors.UnwrapAll(err)) { |
| 96 | return true |
| 97 | } |
| 98 | // If a syscall errno representing ErrNotExist was encoded on a |
| 99 | // different platform, and decoded here, then it will show up as |
| 100 | // neither a syscall errno here nor an ErrNotExist; instead it |
| 101 | // shows up as an OpaqueErrno. We test this here. |
| 102 | if o := (*errbase.OpaqueErrno)(nil); errors.As(err, &o) { |
| 103 | return o.Is(ErrNotExist) |
| 104 | } |
| 105 | return false |
| 106 | } |
| 107 | |
| 108 | // IsTimeout returns a boolean indicating whether the error is known |
| 109 | // to report that a timeout occurred. |
searching dependent graphs…