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
52 lines
1.6 KiB
C
52 lines
1.6 KiB
C
#ifndef JQ_H
|
|
#define JQ_H
|
|
|
|
#include <stdio.h>
|
|
#include <jv.h>
|
|
|
|
enum {JQ_DEBUG_TRACE = 1};
|
|
|
|
typedef struct jq_state jq_state;
|
|
typedef void (*jq_msg_cb)(void *, jv);
|
|
|
|
jq_state *jq_init(void);
|
|
void jq_set_error_cb(jq_state *, jq_msg_cb, void *);
|
|
void jq_get_error_cb(jq_state *, jq_msg_cb *, void **);
|
|
void jq_set_nomem_handler(jq_state *, void (*)(void *), void *);
|
|
jv jq_format_error(jv msg);
|
|
void jq_report_error(jq_state *, jv);
|
|
int jq_compile(jq_state *, const char*);
|
|
int jq_compile_args(jq_state *, const char*, jv);
|
|
void jq_dump_disassembly(jq_state *, int);
|
|
void jq_start(jq_state *, jv value, int);
|
|
jv jq_next(jq_state *);
|
|
void jq_teardown(jq_state **);
|
|
|
|
typedef jv (*jq_input_cb)(jq_state *, void *);
|
|
void jq_set_input_cb(jq_state *, jq_input_cb, void *);
|
|
void jq_get_input_cb(jq_state *, jq_input_cb *, void **);
|
|
|
|
void jq_set_debug_cb(jq_state *, jq_msg_cb, void *);
|
|
void jq_get_debug_cb(jq_state *, jq_msg_cb *, void **);
|
|
|
|
void jq_set_attrs(jq_state *, jv);
|
|
jv jq_get_attrs(jq_state *);
|
|
jv jq_get_jq_origin(jq_state *);
|
|
jv jq_get_prog_origin(jq_state *);
|
|
jv jq_get_lib_dirs(jq_state *);
|
|
void jq_set_attr(jq_state *, jv, jv);
|
|
jv jq_get_attr(jq_state *, jv);
|
|
|
|
typedef struct jq_util_input_state *jq_util_input_state;
|
|
|
|
jq_util_input_state jq_util_input_init(jq_msg_cb, void *);
|
|
void jq_util_input_set_parser(jq_util_input_state, jv_parser *, int);
|
|
void jq_util_input_free(jq_util_input_state *);
|
|
void jq_util_input_add_input(jq_util_input_state, jv);
|
|
int jq_util_input_errors(jq_util_input_state);
|
|
jv jq_util_input_next_input(jq_util_input_state);
|
|
jv jq_util_input_next_input_cb(jq_state *, void *);
|
|
jv jq_util_input_get_position(jq_state*);
|
|
|
|
#endif /* !JQ_H */
|