-
Notifications
You must be signed in to change notification settings - Fork 33
/
errors.go
63 lines (47 loc) · 1.68 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
61
62
63
package catfs
import (
"errors"
"fmt"
)
var (
// ErrStageNotEmpty is returned by Reset() when it was called without force.
// and there are still changes in the staging area.
ErrStageNotEmpty = errors.New("there are changes in the staging area; use the --force")
// ErrNoChange is returned when trying to commit, but there is no change.
ErrNoChange = errors.New("nothing changed between the given versions")
// ErrAmbigiousRev is returned when a ref string could mean several commits.
ErrAmbigiousRev = errors.New("there is more than one rev with this prefix")
// ErrExists is returned if a node already exists at a path, but should not.
ErrExists = errors.New("File exists")
// ErrBadNode is returned when a wrong node type was passed to a method.
ErrBadNode = errors.New("Cannot convert to concrete type. Broken input data?")
)
//////////////
// ErrNoSuchRef is returned when a bad ref was used
type ErrNoSuchRef string
func (e ErrNoSuchRef) Error() string {
return fmt.Sprintf("No ref found named `%s`", string(e))
}
// IsErrNoSuchRef checks if `err` is a no such ref error.
func IsErrNoSuchRef(err error) bool {
_, ok := err.(ErrNoSuchRef)
return ok
}
/////////////////
type errNoSuchFile struct {
path string
}
// Error will return an error description detailin what path is missing.
func (e *errNoSuchFile) Error() string {
return "No such file or directory: " + e.path
}
//////////////
// NoSuchFile creates a new error that reports `path` as missing
func NoSuchFile(path string) error {
return &errNoSuchFile{path}
}
// IsNoSuchFileError asserts that `err` means that the file could not be found
func IsNoSuchFileError(err error) bool {
_, ok := err.(*errNoSuchFile)
return ok
}