-
Notifications
You must be signed in to change notification settings - Fork 1
/
invalid.go
36 lines (28 loc) · 814 Bytes
/
invalid.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 errors
import (
"fmt"
)
type InvalidError struct {
errinfo
}
var formatInvalid = NewDefaultFormatter("is", "invalid", "for")
func ErrInvalid(spec ...string) error {
return &InvalidError{newErrInfo(formatInvalid, spec...)}
}
// ErrInvalidType reports an invalid or unexpected Go type for a dedicated purpose.
func ErrInvalidType(kind string, v interface{}) error {
return &InvalidError{newErrInfo(formatUnknown, kind, fmt.Sprintf("%T", v))}
}
func ErrInvalidWrap(err error, spec ...string) error {
return &InvalidError{wrapErrInfo(err, formatInvalid, spec...)}
}
func IsErrInvalid(err error) bool {
return IsA(err, &InvalidError{})
}
func IsErrInvalidKind(err error, kind string) bool {
var uerr *InvalidError
if err == nil || !As(err, &uerr) {
return false
}
return uerr.kind == kind
}