-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
45 lines (38 loc) · 951 Bytes
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package fs
import (
"errors"
"io/fs"
"os"
"syscall"
)
// AsSyscallPathError() returns a fs.PathError indicating a syscall.Errno.
// Returns nil if err == 0 (aka success)
func AsSyscallPathError(op string, path string, err syscall.Errno) error {
if err == 0 {
return nil
}
return &fs.PathError{op, path, err}
}
// AsPathError() wraps an error in fs.PathError, unwrapping known error
// types, and returning nil if nil is given.
func AsPathError(op string, path string, err error) error {
if err == nil {
return nil
}
switch e2 := err.(type) {
case syscall.Errno:
return AsSyscallPathError(op, path, e2)
case *fs.PathError:
// reuse op and err, not path
op, err = e2.Op, e2.Err
case *os.LinkError:
err = e2.Err
case *os.SyscallError:
err = e2.Err
}
return &fs.PathError{op, path, err}
}
// IsNotImplemented tests if an error is ENOSYS
func IsNotImplemented(err error) bool {
return errors.Is(err, syscall.ENOSYS)
}