-
Notifications
You must be signed in to change notification settings - Fork 4
/
errors.go
58 lines (43 loc) · 1.12 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
package evaluate
import (
"fmt"
"reflect"
"strings"
"github.com/puppetlabs/leg/jsonutil/pkg/jsonpath"
)
type UnsupportedValueError struct {
Type reflect.Type
}
var _ jsonpath.PropagatableError = &UnsupportedValueError{}
func (e *UnsupportedValueError) Error() string {
return fmt.Sprintf("could not evaluate a value of type %s, must be a YAML-compatible type", e.Type)
}
func (e *UnsupportedValueError) Propagate() bool { return true }
type PathEvaluationError struct {
Path string
Cause error
}
var _ jsonpath.PropagatableError = &PathEvaluationError{}
func (e *PathEvaluationError) trace() ([]string, error) {
var path []string
for {
path = append(path, e.Path)
en, ok := e.Cause.(*PathEvaluationError)
if !ok {
return path, e.Cause
}
e = en
}
}
func (e *PathEvaluationError) UnderlyingCause() error {
_, err := e.trace()
return err
}
func (e *PathEvaluationError) Unwrap() error {
return e.Cause
}
func (e *PathEvaluationError) Error() string {
path, err := e.trace()
return fmt.Sprintf("path %q: %+v", strings.Join(path, "."), err)
}
func (e *PathEvaluationError) Propagate() bool { return true }