Skip to content

Commit

Permalink
Fix --stream-errors w/o --stream, and doc+test (close jqlang#2748)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicowilliams committed Jul 23, 2023
1 parent c9c45d7 commit a5ee7e0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
10 changes: 10 additions & 0 deletions docs/content/manual/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ sections:
conjunction with filtering and the `reduce` and `foreach` syntax
to reduce large inputs incrementally.
* `--stream-errors`:
Like `--stream`, but invalid JSON inputs yield array calues
where the first element is the error and the second is a path.
For example, `["a",n]` produces ["Invalid literal at line 1,
column 9",[1]]`.
Implies `--stream`. Invalid JSON inputs produce no error values
when `--stream` without `--stream-errors`.
* `--slurp`/`-s`:
Instead of running the filter for each JSON object in the
Expand Down
9 changes: 9 additions & 0 deletions jq.1.prebuilt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ int main(int argc, char* argv[]) {
continue;
}
if (isoption(argv[i], 0, "stream-errors", &short_opts)) {
parser_flags |= JV_PARSE_STREAM_ERRORS;
parser_flags |= JV_PARSE_STREAMING | JV_PARSE_STREAM_ERRORS;
continue;
}
if (isoption(argv[i], 'e', "exit-status", &short_opts)) {
Expand Down
5 changes: 5 additions & 0 deletions tests/shtest
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ $VALGRIND $Q $JQ -c '. as $d|path(..) as $p|$d|getpath($p)|select((type|. != "ar
$VALGRIND $Q $JQ --stream -c '.|select(length==2)' < "$JQTESTDIR/torture/input0.json" > $d/out1
diff $d/out0 $d/out1

printf '["Unfinished JSON term at EOF at line 1, column 1",[0]]\n' > $d/expected
printf '[' | $VALGRIND $Q $JQ --stream-errors -c . > $d/out 2>&1
diff $d/out $d/expected


## XXX This test can be moved to tests/all.test _now_
clean=false
if which seq > /dev/null 2>&1; then
Expand Down

0 comments on commit a5ee7e0

Please sign in to comment.