/
errors.go
59 lines (49 loc) · 1.33 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
55
56
57
58
59
package types
import (
"fmt"
)
type SchemaError struct {
FieldName string
NestedError error
}
func NewSchemaError(fieldName string, err error) *SchemaError {
fullName := fieldName
nestedErr := err
if schemaErr, ok := err.(*SchemaError); ok {
fullName = fieldName + "." + schemaErr.FieldName
nestedErr = schemaErr.NestedError
}
return &SchemaError{
FieldName: fullName,
NestedError: nestedErr,
}
}
func (s *SchemaError) Error() string {
return fmt.Sprintf("Error parsing schema for field %q: %v", s.FieldName, s.NestedError)
}
type WrongMapValueTypeError struct {
Key string
ExpectedType string
ActualValue interface{}
}
func NewWrongMapValueTypeError(key, expectedType string, actualValue interface{}) *WrongMapValueTypeError {
return &WrongMapValueTypeError{
Key: key,
ExpectedType: expectedType,
ActualValue: actualValue,
}
}
func (w *WrongMapValueTypeError) Error() string {
return fmt.Sprintf("Wrong type for map key %q: expected type %v, got value %q of type %t", w.Key, w.ExpectedType, w.ActualValue, w.ActualValue)
}
type RequiredMapKeyError struct {
Key string
}
func NewRequiredMapKeyError(key string) *RequiredMapKeyError {
return &RequiredMapKeyError{
Key: key,
}
}
func (r *RequiredMapKeyError) Error() string {
return fmt.Sprintf("No value supplied for required map key %q", r.Key)
}