-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
58 lines (47 loc) · 1.39 KB
/
error.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
package accessor
import (
"fmt"
)
// NewNoSuchPathError creates a NoSuchPathError.
func NewNoSuchPathError(message string, key string, keys ...string) *NoSuchPathError {
path := thePhantomPath
for _, k := range keys {
path = path.PushKey(k)
}
return &NoSuchPathError{message, key, path}
}
// NoSuchPathError is returned when no key was found in the object.
type NoSuchPathError struct {
Message string
Key string
Path Path
}
func (e *NoSuchPathError) Error() string {
return fmt.Sprintf("%s: about %q: at %s", e.Message, e.Key, e.Path)
}
// PushKey push key to the head of the stack trace.
func (e *NoSuchPathError) PushKey(key string) {
e.Path = e.Path.PushKey(key)
}
// NewInvalidKeyError createa InvalidKeyError.
func NewInvalidKeyError(v interface{}) error {
return &InvalidKeyError{v}
}
// InvalidKeyError is returned when a key type of the map was not a string.
type InvalidKeyError struct {
Value interface{}
}
func (e *InvalidKeyError) Error() string {
return fmt.Sprintf("cannot use %T(%v) as a object key.", e.Value, e.Value)
}
// NewInvalidPathError creates a InvalidKeyError.
func NewInvalidPathError(message string) error {
return &InvalidPathError{message}
}
// InvalidPathError is returned when failing to create a Path.
type InvalidPathError struct {
Message string
}
func (e *InvalidPathError) Error() string {
return fmt.Sprintf("path is invalid: %s", e.Message)
}