Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fromjson or tonumber error and next jq_compile fails #2091

Closed
diafour opened this issue Mar 31, 2020 · 4 comments
Closed

fromjson or tonumber error and next jq_compile fails #2091

diafour opened this issue Mar 31, 2020 · 4 comments
Labels
Milestone

Comments

@diafour
Copy link

diafour commented Mar 31, 2020

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.

@Sameesunkaria
Copy link
Contributor

Sameesunkaria commented Nov 2, 2020

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.

@diafour
Copy link
Author

diafour commented Nov 3, 2020

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. ;)

@Sameesunkaria
Copy link
Contributor

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. 😕

@itchyny itchyny added the support label Jun 3, 2023
@itchyny itchyny added bug and removed support labels Jun 29, 2023
@itchyny itchyny added this to the 1.7 release milestone Jun 29, 2023
@itchyny
Copy link
Contributor

itchyny commented Jun 30, 2023

This bug was fixed by #2400 (c4d39c4) on May 27, 2022.

@itchyny itchyny closed this as completed Jun 30, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants