-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherrors.go
60 lines (53 loc) · 1.35 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
60
package seltabl
import (
"fmt"
"reflect"
)
// ErrNoDataFound is an error for when no data is found for a selector
type ErrNoDataFound struct {
Typ reflect.Type
Field reflect.StructField
Cfg *SelectorConfig
}
// Error implements the error interface for ErrNoDataFound
func (e ErrNoDataFound) Error() string {
return fmt.Sprintf(
"(%s) [%s] <%s> no data found for selector %s\n html",
e.Typ,
e.Field.Type,
e.Field.Name,
e.Cfg.DataSelector,
)
}
// ErrSelectorNotFound is an error for when a selector is not found
type ErrSelectorNotFound struct {
Typ reflect.Type // type of the struct
Field reflect.StructField // field of the struct
Cfg *SelectorConfig // selector config
}
// Error implements the error interface for ErrSelectorNotFound
func (e ErrSelectorNotFound) Error() string {
return fmt.Sprintf(
"selector %s with type %s not found for field %s with type %s\n html",
e.Cfg.QuerySelector,
e.Typ,
e.Field.Name,
e.Field.Type,
)
}
// ErrParsing is returned when a field's value cannot be parsed.
type ErrParsing struct {
Field reflect.Type
Value string
Err error
}
// Error returns the error message. It implements the error interface.
func (e ErrParsing) Error() string {
return fmt.Sprintf(
"failed to parse field %s of type %s from value %s: %s",
e.Field.Name(),
e.Field.String(),
e.Value,
e.Err,
)
}