diff --git a/processor.go b/processor.go index d063977..32a74d7 100644 --- a/processor.go +++ b/processor.go @@ -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 { @@ -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 { diff --git a/processor_test.go b/processor_test.go index 7345de0..ce7d20b 100644 --- a/processor_test.go +++ b/processor_test.go @@ -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", @@ -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) })