-
Notifications
You must be signed in to change notification settings - Fork 5
/
errors.go
48 lines (36 loc) · 1.37 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
package lenspath
import "fmt"
type EmptyLensPathErr struct{}
func (e *EmptyLensPathErr) Error() string {
return "lenspath: must have at least one lens"
}
type InvalidLensPathErr struct {
index int
errType InvalidLensPathErrType
}
type InvalidLensPathErrType string
const (
ArrayExpectedErr InvalidLensPathErrType = "expected array (*)"
LensPathStoppedErr = "could not navigate further, end of structure reached"
CannotSetFieldErr = "cannot set field"
PathContainsArrErr = "path contains *; use Getter/Setter() instead"
PathDoesntContainsArrErr = "path does not contain *; use Get() instead"
)
func NewInvalidLensPathErr(index int, errType InvalidLensPathErrType) *InvalidLensPathErr {
return &InvalidLensPathErr{index, errType}
}
func (e *InvalidLensPathErr) Error() string {
return fmt.Sprintf("lenspath: %s; lens index: %d", e.errType, e.index)
}
func (e *InvalidLensPathErr) Is(err error) bool {
_, ok := err.(*InvalidLensPathErr)
return ok
}
type InvalidSetParamErr string
const (
ArrayParamExpectedErr InvalidSetParamErr = "expected array for set value"
ParamSizeMismatchErr InvalidSetParamErr = "array param and structure field array length should match"
)
func (e InvalidSetParamErr) Error() string {
return fmt.Sprintf("lenspath: %s", string(e))
}