report filename:line on runtime errors #752
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On runtime errors (ending in invalid state at 'main.c:process()'),
print the input filename and current line number which triggered the
error.
struct jq_util_input_state: add variables
jq_util_input_init(): initialize new variables
jq_util_input_read_more(): update current file/line number on
fgets()
calls.jq_util_input_get_position(): helper functions returning a JV_STRING
containing the current file/line.
strncpyz(): helper function for safe string copy
process(): upon invalid result ('uncaught jq exception'), get the
current input position and print it to stderr.
With this patch, runtime errors printed to stderr will contain the
filename and line of the offending input.
Examples:
With stdin and multiple lines:
With multiple files:
With very long lines (spanning multiple
fgets
calls):With raw input:
Caveat:
The reported line will be the last line of the (valid) parsed JSON data.
Example:
minor ugly hack:
The call the get the current filename/line in 'main.c' is hard-coded
to 'jq_util_input_get_position()' which somewhat bypasses the idea
of using an input callback (e.g. 'jq_set_input_cb()').
But since similar calls to 'jq_utl_input_XXXX' are also hard-coded in
'main.c', the input callback mechanism isn't really generatic at the moment.