Skip to content

fromjson or tonumber error and next jq_compile fails #2091

Closed
@diafour

Description

@diafour

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions