-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
60 lines (50 loc) · 1.89 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package nef
import (
"errors"
"fmt"
)
// IsInvalidPathError
func IsInvalidPathError(err error) bool {
return errors.Is(errors.Unwrap(err), ErrCoreInvalidPath)
}
// NewInvalidPathError
func NewInvalidPathError(description, path string) error {
// should this have a description too to describe the path?
// we probably need a CoreInvalidPathError which InvalidPathError
// wraps.
return fmt.Errorf("description: %q, path: %q, %w",
description, path, ErrCoreInvalidPath,
)
}
// IsBinaryFsOpError
func IsBinaryFsOpError(err error) bool {
return errors.Is(err, ErrCoreBinaryFsOp)
}
// NewInvalidBinaryFsOpError
func NewInvalidBinaryFsOpError(op, from, to string) error {
return fmt.Errorf("op: %q, from %q, to: %q %w", op, from, to, ErrCoreBinaryFsOp)
}
// IsRejectSameDirMoveError
func IsRejectSameDirMoveError(err error) bool {
return errors.Is(err, ErrCoreRejectSameDirMove)
}
// NewRejectSameDirMoveError
func NewRejectSameDirMoveError(op, from, to string) error {
return fmt.Errorf("op: %q, from %q, to: %q %w", op, from, to, ErrCoreRejectSameDirMove)
}
// IsRejectDifferentDirChangeError
func IsRejectDifferentDirChangeError(err error) bool {
return errors.Is(err, ErrCoreRejectDifferentDirChange)
}
// NewRejectDifferentDirChangeError
func NewRejectDifferentDirChangeError(op, from, to string) error {
return fmt.Errorf("op: %q, from %q, to: %q %w", op, from, to, ErrCoreRejectDifferentDirChange)
}
// these errors are deliberately being exported, so that client libraries (eg traverse) that do support i18n
// can wrap them and make them translate-able.
var (
ErrCoreInvalidPath = errors.New("invalid path")
ErrCoreBinaryFsOp = errors.New("invalid binary file system operation")
ErrCoreRejectSameDirMove = errors.New("same directory move rejected, use move instead")
ErrCoreRejectDifferentDirChange = errors.New("different directory change rejected, use move instead")
)