-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherrors.go
36 lines (32 loc) · 1.2 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
package mutable
import (
"errors"
"fmt"
"reflect"
"strings"
)
var (
errCannotSetValue = func(field string, value interface{}) error {
return fmt.Errorf("cannot set value (%v) to the field (%v)", value, field)
}
errCannotFind = func(field string) error {
return fmt.Errorf("cannot find a destination field (%v)", field)
}
errNotPointer = errors.New("given value is not a Pointer type")
errNestedResetError = errors.New("cannot reset nested mutable object")
errNotSettable = errors.New("field is not settable")
errNotInterfaceable = errors.New("field is not interfaceable")
errCannotParse = errors.New("cannot parse value")
errUnsupportedType = func(fieldType reflect.Type, value interface{}) error {
return fmt.Errorf("unsupported value type (%T) for a field (%v)", value, fieldType)
}
errNotJSON = errors.New("not a valid JSON value")
)
// IsCannotSetErr reports whether an err is a errCannotSetValue error
func IsCannotSetErr(err error) bool {
return strings.HasPrefix(err.Error(), "cannot set value")
}
// IsCannotFindErr reports whether an err is a errCannotFind error
func IsCannotFindErr(err error) bool {
return strings.HasPrefix(err.Error(), "cannot find a destination field")
}