-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
43 lines (33 loc) · 872 Bytes
/
error.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
package tagrunner
import (
"errors"
"fmt"
jsoniter "github.com/json-iterator/go"
)
var (
ErrRunnerNil = errors.New("runner is nil")
ErrInvalidInput = errors.New("invalid input")
ErrInvalidTagPattern = errors.New("invalid tag pattern")
)
type RunnerError struct {
TagKey string `json:"tag_key"`
TagValue string `json:"tag_value"`
TagArgs []string `json:"tag_args"`
FieldStructName string `json:"field_struct_name"`
FieldLabelName string `json:"field_label_name"`
PassBy interface{} `json:"pass_by"`
raw error
}
func (r RunnerError) Error() string {
return fmt.Sprintf("%s\n%s", r.raw.Error(), marshal(r))
}
func (r *RunnerError) Unwrap() error {
if r == nil {
return nil
}
return r.raw
}
func marshal(o interface{}) string {
s, _ := jsoniter.MarshalToString(o)
return s
}