Skip to content

Commit

Permalink
Error message TODO
Browse files Browse the repository at this point in the history
  • Loading branch information
draxil committed Nov 26, 2022
1 parent e5be0f9 commit ec87e76
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (p processor) handleNonArray(j *json.JSON, clue byte, topLevel bool) error
return errNotArrayWas(guessJSONType(j.Peek()))
}
if !json.SaneValueStart(clue) {
return errPathLeadToBadValue(clue)
return errPathLeadToBadValue(clue, p.options.Path)
}

for {
Expand Down Expand Up @@ -246,15 +246,14 @@ func errBadPath(chunk string) error {
func errBlankPath() error {
return fmt.Errorf("bad blank path node, did you have a double dot?")
}
func errPathLeadToBadValue(start byte) error {
func errPathLeadToBadValue(start byte, path string) error {
t := guessJSONType(start)

// TODO: reference the path
if t != "" {
return fmt.Errorf("path lead to %s not an object", t)
return fmt.Errorf("path (%s) lead to %s not an object", path, t)
}

return fmt.Errorf("path lead to bad value start: %c", start)
return fmt.Errorf("path (%s) lead to bad value start: %c", path, start)
}

func errBadArrayValueStart(start byte, index int) error {
Expand Down
4 changes: 2 additions & 2 deletions processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestProcessor(t *testing.T) {
opts: options.Set{
Path: "something",
},
expErr: errPathLeadToBadValue('b'),
expErr: errPathLeadToBadValue('b', "something"),
},
{
name: "path leads to a number",
Expand Down Expand Up @@ -451,7 +451,7 @@ func TestErrPathLeadToBadValueMessage(t *testing.T) {

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
err := errPathLeadToBadValue(tc.clue)
err := errPathLeadToBadValue(tc.clue, "xyz")
str := err.Error()
assert.Contains(t, str, tc.contains)
})
Expand Down

0 comments on commit ec87e76

Please sign in to comment.