fromjson or tonumber error and next jq_compile fails
diafour opened this issue · comments
First of all, this problem is reproduced when using jq
as a library inside your program. I am executing an expression with tonumber
or fromjson
and if input is not valid, then the next call to jq_compile
fails with this dump:
jq: error: Invalid numeric literal at EOF at line 1, column 1 (while parsing '5') at <builtin>, line 1:
def halt_error: halt_error(5);
jq: error: Invalid numeric literal at EOF at line 1, column 1 (while parsing '0') at <builtin>, line 7:
def unique: group_by(.) | map(.[0]);
jq: error: Invalid numeric literal at EOF at line 1, column 1 (while parsing '0') at <builtin>, line 8:
def unique_by(f): group_by(f) | map(.[0]);
... more lines related to parsing builtins.inc ...
jq: error: Invalid numeric literal at EOF at line 1, column 1 (while parsing '0') at <builtin>, line 248:
else (-1 -.[0])
jq: error: Invalid numeric literal at EOF at line 1, column 1 (while parsing '2') at <builtin>, line 250:
else .[2]
jq: src/builtin.c:1806: builtins_bind: Assertion `!nerrors' failed.
You can reproduce this bug with make check
and this test at the start of tests/jq.test
:
try (tonumber) catch ("Should catch error")
"a20"
"Should catch error"
Or with fromjson
:
try (fromjson) catch ("Should catch error")
"a20"
"Should catch error"
The test is passed, but next test fails to compile with the described problem.
I've put jq.test
and test-suite.log
here: https://gist.github.com/diafour/3b3d8f123b642ff095c41c16d6f32d0e
As you can see, the output is not for the last commit in the master branch, but for jq 1.6-99-gcf4b48c-dirty
(cf4b48c). That's the first commit with this problem. The previous commit, b6be13d works great.
I see changes related to try/catch and find this issue #1859, but I don't know if this is related.
@nicowilliams can you help with this? I can make more tests if needed.
Hey @diafour ! 👋
Any updates on this issue?
I am experiencing a similar issue while using jq as a library. I have .
as my query, and an intentionally invalid json something
(no quotes, just some text).
On the first execution, it fails with a parse error, and on the second execution, I see the same failure on jq_parse_library
.
Hey @Sameesunkaria !
No updates, I've simply stuck to the b6be13d. This commit is "good enough": it has no performance problem as a 1.6 tag and works well as a library.
It will be great to fix this failure, but my fingers become frozen when I hear the word gdb
. ;)
Hahaha
I am sticking to the 1.6 release for now. I haven't experience any performance issues for my use case. I would have liked to fix the issue, but I have next to no experience in c. 😕