Skip to content

Commit

Permalink
Update error message
Browse files Browse the repository at this point in the history
  • Loading branch information
tidwall committed Sep 4, 2021
1 parent 0bc94ab commit 64a7cf9
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions sjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package sjson

import (
jsongo "encoding/json"
"errors"
"sort"
"strconv"
"unsafe"
Expand Down Expand Up @@ -548,8 +547,6 @@ func set(jstr, path, raw string,
return buf, nil
}
}
// parse the path, make sure that it does not contain invalid characters
// such as '#', '?', '*'
var paths []pathResult
r, simple := parsePath(path)
if simple {
Expand All @@ -565,7 +562,7 @@ func set(jstr, path, raw string,
if !simple {
if del {
return []byte(jstr),
errors.New("cannot delete value from a complex path")
&errorType{"cannot delete value from a complex path"}
}
return setComplexPath(jstr, path, raw, stringify)
}
Expand All @@ -579,7 +576,7 @@ func set(jstr, path, raw string,
func setComplexPath(jstr, path, raw string, stringify bool) ([]byte, error) {
res := gjson.Get(jstr, path)
if !res.Exists() || !(res.Index != 0 || len(res.Indexes) != 0) {
return []byte(jstr), errors.New("no values found at path")
return []byte(jstr), errNoChange
}
if res.Index != 0 {
njson := []byte(jstr[:res.Index])
Expand All @@ -602,8 +599,7 @@ func setComplexPath(jstr, path, raw string, stringify bool) ([]byte, error) {
return true
})
if len(res.Indexes) != len(vals) {
return []byte(jstr),
errors.New("could not set value due to index mismatch")
return []byte(jstr), errNoChange
}
for i := 0; i < len(res.Indexes); i++ {
vals[i].index = res.Indexes[i]
Expand Down

0 comments on commit 64a7cf9

Please sign in to comment.