-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Describe the bug
When a script file contains certain classes of syntax errors, jq crashes with an assertion failure rather than reporting a syntax error.
To Reproduce
bug.jq
, stored in ~/.jq/bug.jq
def bug: sub("a"; "b";
Crashes upon include
:
jq -n 'include "bug"; .'
Assertion failed: (end > loc.start), function locfile_locate, file locfile.c, line 82.
Abort trap: 6
Crashes upon import
:
jq -n 'import "bug" as bug; .'
Assertion failed: (end > loc.start), function locfile_locate, file locfile.c, line 82.
Abort trap: 6
Crashes as main script file:
$ jq -f ~/.jq/bug.jq
Assertion failed: (end > loc.start), function locfile_locate, file locfile.c, line 82.
Abort trap: 6
Expected behavior
When I fix the syntax within bug.jq
slightly but not completely, jq correctly reports a syntax/compile error. This is the expected/desired behavior for the above case.
bug.jq
, stored in ~/.jq/bug.jq
def bug: sub("a"; "b";)
Note I added )
at the end of the line.
Syntax/comple error upon include
:
jq -n 'include "bug"; .'
jq: error: syntax error, unexpected ')' at /Users/REDACTED/.jq/bug.jq, line 1, column 23:
def bug: sub("a"; "b";)
^
jq: 1 compile error
And upon import
:
jq -n 'import "bug" as bug; .'
jq: error: syntax error, unexpected ')' at /Users/REDACTED/.jq/bug.jq, line 1, column 23:
def bug: sub("a"; "b";)
^
jq: 1 compile error
And when used as main script file:
$ jq -f ~/.jq/bug.jq
jq: error: syntax error, unexpected ')' at <top-level>, line 1, column 23:
def bug: sub("a"; "b";)
^
jq: 1 compile error
Environment (please complete the following information):
macOS Sonoma 14.7.5 on Apple MacBook Pro, Apple M3 silicon
$ uname -a
Darwin OPLN-L-7P6VP6HQ 23.6.0 Darwin Kernel Version 23.6.0: Thu Mar 6 22:00:07 PST 2025; root:xnu-10063.141.1.704.6~1/RELEASE_ARM64_T6030 arm64
Version 1.8.0 installed via Homebrew:
$ command -v jq
/opt/homebrew/bin/jq
$ jq --version
jq-1.8.0
Additional context
This is not the best way to report a syntax error. The program does halt for good reason, just in a less pleasant way. I don't consider this a severe or urgent bug, just a moderate debugging impediment.