Skip to content

Commit

Permalink
fix(src): use errors.Is(err, fs.ErrNotExist)
Browse files Browse the repository at this point in the history
I implemented fs.FS. When the file does not exist, `xerrors.Wrap(fs.ErrNotExist, "")` will be returned. However, `os.IsNotExist` cannot handle this situation. I found the following comment:
```
// 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, fs.ErrNotExist).
```

Therefore, we should use `errors.Is(err, fs.ErrNotExist)` instead.
  • Loading branch information
laushunyu committed Jun 14, 2023
1 parent 68a430f commit 6447a67
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion interp/src.go
@@ -1,6 +1,7 @@
package interp

import (
"errors"
"fmt"
"io/fs"
"os"
Expand Down Expand Up @@ -245,7 +246,7 @@ func previousRoot(filesystem fs.FS, rootPath, root string) (string, error) {
vendored = strings.TrimPrefix(strings.TrimPrefix(parent, prefix), string(filepath.Separator))
break
}
if !os.IsNotExist(err) {
if !errors.Is(err, fs.ErrNotExist) {
return "", err
}
// stop when we reach GOPATH/src
Expand Down

0 comments on commit 6447a67

Please sign in to comment.