-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
47 lines (40 loc) · 950 Bytes
/
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
package injector
import (
"fmt"
"reflect"
)
type ErrNonStructPointer struct {
TargetType reflect.Type
}
func (e *ErrNonStructPointer) Error() string {
return fmt.Sprintf(
"Can't inject into non-struct pointer of type '%s'",
e.TargetType.String(),
)
}
type ErrFieldValueTypeMismatch struct {
TargetType reflect.Type
FieldName string
FieldType reflect.Type
ValueType reflect.Type
}
func (e *ErrFieldValueTypeMismatch) Error() string {
return fmt.Sprintf(
"Failed to inject into struct of type '%s' since field '%s' of type '%s' does not match injected value of type '%s'",
e.TargetType.String(),
e.FieldName,
e.FieldType.String(),
e.ValueType.String(),
)
}
type ErrRequiredStructField struct {
FieldName string
TargetType reflect.Type
}
func (e *ErrRequiredStructField) Error() string {
return fmt.Sprintf(
"Nothing provided for required field '%s' on struct '%s'",
e.FieldName,
e.TargetType.String(),
)
}