summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Williams <nico@cryptonector.com>2023-07-23 00:01:52 -0500
committerNico Williams <nico@cryptonector.com>2023-07-23 03:33:28 -0500
commitf64ef1a7d7836ee60fb277d49302661af630d6c1 (patch)
tree8b68318f115e3d2db9ee4026e798a9a48bb2d441
parent123c78060773844866b964a67c6c21760aa9f701 (diff)
Fix --stream-errors w/o --stream, and doc+test (close #2748)
-rw-r--r--docs/content/manual/manual.yml10
-rw-r--r--jq.1.prebuilt9
-rw-r--r--src/main.c2
-rwxr-xr-xtests/shtest5
4 files changed, 25 insertions, 1 deletions
diff --git a/docs/content/manual/manual.yml b/docs/content/manual/manual.yml
index 6568ec1e..157bdc42 100644
--- a/docs/content/manual/manual.yml
+++ b/docs/content/manual/manual.yml
@@ -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
diff --git a/jq.1.prebuilt b/jq.1.prebuilt
index 934f0e7b..8df532e3 100644
--- a/jq.1.prebuilt
+++ b/jq.1.prebuilt
@@ -73,6 +73,15 @@ Parse the input in streaming fashion, outputting arrays of path and leaf values
This is useful for processing very large inputs\. Use this in conjunction with filtering and the \fBreduce\fR and \fBforeach\fR syntax to reduce large inputs incrementally\.
.
.TP
+\fB\-\-stream\-errors\fR:
+.
+.IP
+Like \fB\-\-stream\fR, but invalid JSON inputs yield array calues where the first element is the error and the second is a path\. For example, \fB["a",n]\fR produces ["Invalid literal at line 1, column 9",[1]]`\.
+.
+.IP
+Implies \fB\-\-stream\fR\. Invalid JSON inputs produce no error values when \fB\-\-stream\fR without \fB\-\-stream\-errors\fR\.
+.
+.TP
\fB\-\-slurp\fR/\fB\-s\fR:
.
.IP
diff --git a/src/main.c b/src/main.c
index 466a8870..99857c21 100644
--- a/src/main.c
+++ b/src/main.c
@@ -465,7 +465,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)) {
diff --git a/tests/shtest b/tests/shtest
index b2b8571d..1ee84d3a 100755
--- a/tests/shtest
+++ b/tests/shtest
@@ -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