Added better error reporting

This commit is contained in:
Mike Farah 2020-12-17 14:19:46 +11:00
parent a96b74e779
commit bb088f6aa2
2 changed files with 6 additions and 1 deletions

View File

@ -71,7 +71,7 @@ func (p *pathTreeCreator) CreatePathTree(postFixPath []*Operation) (*PathTreeNod
stack = append(stack, &newNode)
}
if len(stack) != 1 {
return nil, fmt.Errorf("expected stack to have 1 thing but its %v", stack)
return nil, fmt.Errorf("expected end of expression but found '%v', please check expression syntax", strings.TrimSpace(stack[1].Operation.StringValue))
}
return stack[0], nil
}

View File

@ -35,3 +35,8 @@ func TestPathTreeOneArgForOneArgOp(t *testing.T) {
_, err := treeCreator.ParsePath("explode(.)")
test.AssertResultComplex(t, nil, err)
}
func TestPathTreeExtraArgs(t *testing.T) {
_, err := treeCreator.ParsePath("sortKeys(.) explode(.)")
test.AssertResultComplex(t, "expected end of expression but found 'explode', please check expression syntax", err.Error())
}