55 "strconv"
66 "strings"
77
8+ "github.com/launchdarkly/go-sdk-common/v3/lderrors"
89 "github.com/launchdarkly/go-sdk-common/v3/ldvalue"
910
1011 "github.com/launchdarkly/go-jsonstream/v2/jreader"
@@ -81,7 +82,7 @@ type attrRefComponent struct {
8182// parameter will consider it invalid.
8283func NewRef (referenceString string ) Ref {
8384 if referenceString == "" || referenceString == "/" {
84- return Ref {err : errAttributeEmpty , rawPath : referenceString }
85+ return Ref {err : lderrors. ErrAttributeEmpty {} , rawPath : referenceString }
8586 }
8687 if referenceString [0 ] != '/' {
8788 // When there is no leading slash, this is a simple attribute reference with no character escaping.
@@ -94,18 +95,18 @@ func NewRef(referenceString string) Ref {
9495 if unescaped , ok := unescapePath (path ); ok {
9596 return Ref {singlePathComponent : unescaped , rawPath : referenceString }
9697 }
97- return Ref {err : errAttributeInvalidEscape , rawPath : referenceString }
98+ return Ref {err : lderrors. ErrAttributeInvalidEscape {} , rawPath : referenceString }
9899 }
99100 parts := strings .Split (path , "/" )
100101 ret := Ref {rawPath : referenceString , components : make ([]attrRefComponent , 0 , len (parts ))}
101102 for _ , p := range parts {
102103 if p == "" {
103- ret .err = errAttributeExtraSlash
104+ ret .err = lderrors. ErrAttributeExtraSlash {}
104105 return ret
105106 }
106107 unescaped , ok := unescapePath (p )
107108 if ! ok {
108- return Ref {err : errAttributeInvalidEscape , rawPath : referenceString }
109+ return Ref {err : lderrors. ErrAttributeInvalidEscape {} , rawPath : referenceString }
109110 }
110111 component := attrRefComponent {name : unescaped }
111112 if p [0 ] >= '0' && p [0 ] <= '9' {
@@ -129,7 +130,7 @@ func NewRef(referenceString string) Ref {
129130// or to ldattr.NewRef("/a~1b").
130131func NewLiteralRef (attrName string ) Ref {
131132 if attrName == "" {
132- return Ref {err : errAttributeEmpty , rawPath : attrName }
133+ return Ref {err : lderrors. ErrAttributeEmpty {} , rawPath : attrName }
133134 }
134135 if attrName [0 ] != '/' {
135136 // When there is no leading slash, this is a simple attribute reference with no character escaping.
@@ -162,13 +163,9 @@ func (a Ref) Equal(other Ref) bool {
162163
163164// Err returns nil for a valid Ref, or a non-nil error value for an invalid Ref.
164165//
165- // A Ref can only be invalid for the following reasons:
166- //
167- // 1. The input string was empty, or consisted only of "/".
168- //
169- // 2. A slash-delimited string had a double slash causing one component to be empty, such as "/a//b".
170- //
171- // 3. A slash-delimited string contained a "~" character that was not followed by "0" or "1".
166+ // A Ref is invalid if the input string is empty, or starts with a slash but is not a valid
167+ // slash-delimited path, or starts with a slash and contains an invalid escape sequence. For a list of
168+ // the possible validation errors, see the ErrAttribute___ types in the lderrors package.
172169//
173170// Otherwise, the Ref is valid, but that does not guarantee that such an attribute exists in any
174171// given Context. For instance, NewRef("name") is a valid Ref, but a specific Context might or might
@@ -177,7 +174,7 @@ func (a Ref) Equal(other Ref) bool {
177174// See comments on the Ref type for more details of the attribute reference syntax.
178175func (a Ref ) Err () error {
179176 if a .err == nil && a .rawPath == "" {
180- return errAttributeEmpty
177+ return lderrors. ErrAttributeEmpty {}
181178 }
182179 return a .err
183180}
0 commit comments