Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/fs: Use io/fs errors as recommended in std lib #8726

Merged
merged 2 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 13 additions & 7 deletions lib/fs/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"context"
"errors"
"io"
"io/fs"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -192,20 +193,25 @@ const OptWriteOnly = os.O_WRONLY
// as an error by any function.
var SkipDir = filepath.SkipDir

// IsExist is the equivalent of os.IsExist
var IsExist = os.IsExist
func IsExist(err error) bool {
return errors.Is(err, ErrExist)
}

// IsExist is the equivalent of os.ErrExist
var ErrExist = os.ErrExist
// ErrExist is the equivalent of os.ErrExist
var ErrExist = fs.ErrExist

// IsNotExist is the equivalent of os.IsNotExist
var IsNotExist = os.IsNotExist
func IsNotExist(err error) bool {
return errors.Is(err, ErrNotExist)
}

// ErrNotExist is the equivalent of os.ErrNotExist
var ErrNotExist = os.ErrNotExist
var ErrNotExist = fs.ErrNotExist

// IsPermission is the equivalent of os.IsPermission
var IsPermission = os.IsPermission
func IsPermission(err error) bool {
return errors.Is(err, fs.ErrPermission)
}

// IsPathSeparator is the equivalent of os.IsPathSeparator
var IsPathSeparator = os.IsPathSeparator
Expand Down
4 changes: 2 additions & 2 deletions lib/ignore/ignore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -996,8 +996,8 @@ func TestIssue4901(t *testing.T) {
if err == nil {
t.Fatal("expected an error")
}
if fs.IsNotExist(err) {
t.Fatal("unexpected error type")
if err == fs.ErrNotExist {
t.Fatalf("unexpected error type: %T", err)
}
if !IsParseError(err) {
t.Fatal("failure to load included file should be a parse error")
Expand Down