itchyny / gojq

Pure Go implementation of jq
MIT License
3.3k stars 119 forks source link

query position of failed Run() #177

Closed chrisplo closed 2 years ago

chrisplo commented 2 years ago

Would be great to know where in the query the runtime fails, such as during a type problem. example:

$ echo '"foo"' | ~/go/bin/gojq '(1==1).foo'
gojq: expected an object but got: boolean (true)

while this example is trivial, with a very large query it can be very ambiguous.

itchyny commented 2 years ago

I understand the request, but this is difficult to support in this project. Currently gojq syntax tree does not have the position in the query string and it is impossible for the compiler to tell the position. Even if it does, the compiler drops various information of the syntax tree, such as variable names. Supporting the position on failure case is expected to introduce considerable overhead for normal use cases as well. This feature is unlikely to be implemented, so sorry but closing.