...
1 package evaluation
2
3 import (
4 "fmt"
5
6 "github.com/launchdarkly/go-sdk-common/v3/ldreason"
7 )
8
9
10
11
12
13
14
15
16
17 type evalError interface {
18 error
19 errorKind() ldreason.EvalErrorKind
20 }
21
22
23 func errorKindForError(err error) ldreason.EvalErrorKind {
24 if e, ok := err.(evalError); ok {
25 return e.errorKind()
26 }
27 return ldreason.EvalErrorException
28 }
29
30
31 type badVariationError int
32
33 func (e badVariationError) Error() string {
34 return fmt.Sprintf("rule, fallthrough, or target referenced a nonexistent variation index %d", int(e))
35 }
36
37 func (e badVariationError) errorKind() ldreason.EvalErrorKind {
38 return ldreason.EvalErrorMalformedFlag
39 }
40
41
42 type emptyAttrRefError struct{}
43
44 func (e emptyAttrRefError) Error() string {
45 return "rule clause did not specify an attribute"
46 }
47
48 func (e emptyAttrRefError) errorKind() ldreason.EvalErrorKind {
49 return ldreason.EvalErrorMalformedFlag
50 }
51
52
53
54 type badAttrRefError string
55
56 func (e badAttrRefError) Error() string {
57 return fmt.Sprintf("invalid attribute reference %q", string(e))
58 }
59
60 func (e badAttrRefError) errorKind() ldreason.EvalErrorKind {
61 return ldreason.EvalErrorMalformedFlag
62 }
63
64
65 type emptyRolloutError struct{}
66
67 func (e emptyRolloutError) Error() string {
68 return "rollout or experiment with no variations"
69 }
70
71 func (e emptyRolloutError) errorKind() ldreason.EvalErrorKind {
72 return ldreason.EvalErrorMalformedFlag
73 }
74
75
76
77 type circularPrereqReferenceError string
78
79 func (e circularPrereqReferenceError) Error() string {
80 return fmt.Sprintf("prerequisite relationship to %q caused a circular reference;"+
81 " this is probably a temporary condition due to an incomplete update", string(e))
82 }
83
84 func (e circularPrereqReferenceError) errorKind() ldreason.EvalErrorKind {
85 return ldreason.EvalErrorMalformedFlag
86 }
87
88
89
90 type circularSegmentReferenceError string
91
92 func (e circularSegmentReferenceError) Error() string {
93 return fmt.Sprintf("segment rule referencing segment %q caused a circular reference;"+
94 " this is probably a temporary condition due to an incomplete update", string(e))
95 }
96
97
98 type malformedSegmentError struct {
99 SegmentKey string
100 Err error
101 }
102
103 func (e malformedSegmentError) Error() string {
104 return fmt.Sprintf("segment %q had an invalid configuration: %s", e.SegmentKey, e.Err)
105 }
106
107 func (e malformedSegmentError) errorKind() ldreason.EvalErrorKind {
108 return ldreason.EvalErrorMalformedFlag
109
110 }
111
View as plain text