-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy patherrors.go
More file actions
110 lines (84 loc) · 3.69 KB
/
errors.go
File metadata and controls
110 lines (84 loc) · 3.69 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package evaluation
import (
"fmt"
"github.com/launchdarkly/go-sdk-common/v3/ldreason"
)
// These error types are used only internally to distinguish between reasons an evaluation might fail.
// They are surfaced only in terms of the EvaluationReason/ErrorKind types.
// When possible, we define these types as renames of a simple type like string or int, rather than as
// a struct. This is a minor optimization to take advantage of the fact that a simple type that implements
// an interface does not need to be allocated on the heap.
// EvalError is an internal interface for an error that should cause evaluation to fail.
type evalError interface {
error
errorKind() ldreason.EvalErrorKind
}
// ErrorKindForError returns the appropriate ldreason.EvalErrorKind value for an error.
func errorKindForError(err error) ldreason.EvalErrorKind {
if e, ok := err.(evalError); ok {
return e.errorKind()
}
return ldreason.EvalErrorException
}
// BadVariationError means a variation index was out of range. The integer value is the index.
type badVariationError int
func (e badVariationError) Error() string {
return fmt.Sprintf("rule, fallthrough, or target referenced a nonexistent variation index %d", int(e))
}
func (e badVariationError) errorKind() ldreason.EvalErrorKind {
return ldreason.EvalErrorMalformedFlag
}
// EmptyAttrRefError means an attribute reference in a clause was undefined
type emptyAttrRefError struct{}
func (e emptyAttrRefError) Error() string {
return "rule clause did not specify an attribute"
}
func (e emptyAttrRefError) errorKind() ldreason.EvalErrorKind {
return ldreason.EvalErrorMalformedFlag
}
// BadAttrRefError means an attribute reference in a clause was syntactically invalid. The string value is the
// attribute reference.
type badAttrRefError string
func (e badAttrRefError) Error() string {
return fmt.Sprintf("invalid attribute reference %q", string(e))
}
func (e badAttrRefError) errorKind() ldreason.EvalErrorKind {
return ldreason.EvalErrorMalformedFlag
}
// EmptyRolloutError means a rollout or experiment had no variations.
type emptyRolloutError struct{}
func (e emptyRolloutError) Error() string {
return "rollout or experiment with no variations"
}
func (e emptyRolloutError) errorKind() ldreason.EvalErrorKind {
return ldreason.EvalErrorMalformedFlag
}
// CircularPrereqReferenceError means there was a cycle in prerequisites. The string value is the key of the
// prerequisite.
type circularPrereqReferenceError string
func (e circularPrereqReferenceError) Error() string {
return fmt.Sprintf("prerequisite relationship to %q caused a circular reference;"+
" this is probably a temporary condition due to an incomplete update", string(e))
}
func (e circularPrereqReferenceError) errorKind() ldreason.EvalErrorKind {
return ldreason.EvalErrorMalformedFlag
}
// CircularSegmentReferenceError means there was a cycle in segment rules. The string value is the key of the
// segment where we detected the cycle.
type circularSegmentReferenceError string
func (e circularSegmentReferenceError) Error() string {
return fmt.Sprintf("segment rule referencing segment %q caused a circular reference;"+
" this is probably a temporary condition due to an incomplete update", string(e))
}
// MalformedSegmentError means invalid properties were found while trying to match a segment.
type malformedSegmentError struct {
SegmentKey string
Err error
}
func (e malformedSegmentError) Error() string {
return fmt.Sprintf("segment %q had an invalid configuration: %s", e.SegmentKey, e.Err)
}
func (e malformedSegmentError) errorKind() ldreason.EvalErrorKind {
return ldreason.EvalErrorMalformedFlag
// Technically it's not a malformed *flag*, but we don't have a better error code for this.
}