-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report filename:line on runtime errors (fix #752)
With this patch, jq run-time errors printed to stderr will contain the filename and line of the offending input. But note that the JSON text parser does (yet) print the input filename on parse error. A jq run-time error is a jq program error, not including syntax errors nor JSON text input format errors. Examples: With stdin and multiple lines: $ printf '{"a":43}\n{"a":{"b":66}}\n' | ./jq '.a+1' 44 jq: error (at stdin:2): object and number cannot be added With multiple files: $ printf '{"a":43}' > 1.json $ printf '{"a":"hello"}\n' > 2.json $ printf '{"a":{"b":66}}\n' > 3.json $ ./jq '[.a]|@TSV' 1.json 2.json 3.json "43" "hello" jq: error (at 3.json:1): object is not valid in a csv row With very long lines (spanning multiple `fgets` calls): $ ( printf '{"a":43}\n' ; printf '{"a":{"b":[' ; seq 10000 | paste -d, -s | tr -d '\n' ; printf ']}}\n' ; printf '{"a":"hello"}\n' ) | ./jq '[.a] | @TSV' "43" jq: error (at stdin:2): object is not valid in a csv row "hello" With raw input: $ seq 1000 | ./jq --raw-input 'select(.=="700") | . + 10' jq: error (at stdin:700): string and number cannot be added Caveat: The reported line will be the last line of the (valid) parsed JSON data. Example: $ printf '{\n"a":\n"hello"\n\n\n}\n' | ./jq '.a+4' jq: error (at stdin:6): string and number cannot be added
- Loading branch information
1 parent
2e25756
commit a6460f4
Showing
3 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters