gojq icon indicating copy to clipboard operation
gojq copied to clipboard

Add files/line/column to run errors like iteratorError?

Open LeonB opened this issue 1 year ago • 5 comments

Would it be feasible and wanted to add files/line/column to things like iterator errors?

I had something in mind like:

Error: Cannot iterate over null (null): test.jq:4
    4 |   | null | map({})
                   ^^^  Cannot iterate over null (null)

LeonB avatar Jun 18 '24 14:06 LeonB

Looked into goyacc but I don't see an obvious way to pass the offset into Query/AST.

LeonB avatar Sep 21 '24 22:09 LeonB

Hey! that would be nice. jq-lsp uses a modified version of gojq's parser to keep track of token positions, might be a start. To get positions for runtime errors i think you would also have to pass along things while compiling.

wader avatar Sep 22 '24 08:09 wader

@wader thanks! I'll look into it.

LeonB avatar Sep 22 '24 18:09 LeonB

gojq is executing bytecodes which I didn't know. Adding offset to every bytecode would be a bit much I expect, so I think something like a symbol table should be implemented where we link opcodes to the corresponding symbols and offsets. The codeinfo would be a nice start.

@wader do you have any thoughts about how to implement something like that?

LeonB avatar Sep 22 '24 21:09 LeonB

No good ideas really, i would guess some kind of location info needs to be tracked on the stack during execution? maybe @itchyny has some ideas? looking at the codeinfo stuff atm it seems to be debug only, so maybe also needs to consider how much performance impact it would have

wader avatar Sep 23 '24 08:09 wader