-
Notifications
You must be signed in to change notification settings - Fork 5
/
errors.go
54 lines (44 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package qs
import (
"fmt"
"reflect"
)
// IsRequiredFieldError returns ok==false if the given error wasn't caused by a
// required field that was missing from the query string.
// Otherwise it returns the name of the missing required field with ok==true.
func IsRequiredFieldError(e error) (fieldName string, ok bool) {
if re, ok := e.(*reqError); ok {
return re.FieldName, true
}
return "", false
}
// reqError is returned when a struct field marked with the 'req' option isn't
// in the unmarshaled url.Values or query string.
type reqError struct {
Message string
FieldName string
}
func (e *reqError) Error() string {
return e.Message
}
type wrongTypeError struct {
Actual reflect.Type
Expected reflect.Type
}
func (e *wrongTypeError) Error() string {
return fmt.Sprintf("received type %v, want %v", e.Actual, e.Expected)
}
type wrongKindError struct {
Actual reflect.Type
Expected reflect.Kind
}
func (e *wrongKindError) Error() string {
return fmt.Sprintf("received type %v of kind %v, want kind %v",
e.Actual, e.Actual.Kind(), e.Expected)
}
type unhandledTypeError struct {
Type reflect.Type
}
func (e *unhandledTypeError) Error() string {
return fmt.Sprintf("unhandled type: %v", e.Type)
}