-
Notifications
You must be signed in to change notification settings - Fork 2
/
errors.go
43 lines (37 loc) · 1.13 KB
/
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
package errors
import "io/fs"
type (
// Kind specifies a type of error.
Kind uint8
// Error wraps a [fs.PathError]
// with an error [Kind].
Error struct {
fs.PathError
Kind
}
)
//go:generate stringer -type=Kind
const (
Other Kind = iota // Unclassified error.
InvalidItem // Invalid operation for the item being operated on.
InvalidOperation // Operation itself is not valid within the system.
Permission // Permission denied.
IO // External I/O error such as network failure.
Exist // Item already exists.
NotExist // Item does not exist.
IsDir // Item is a directory.
NotDir // Item is not a directory.
NotEmpty // Directory not empty.
ReadOnly // File system has no modification capabilities.
)
func (e *Error) Unwrap() error { return &e.PathError }
func New(op, path string, err error, kind Kind) error {
return &Error{
PathError: fs.PathError{
Op: op,
Path: path,
Err: err,
},
Kind: kind,
}
}