Skip to content

Commit

Permalink
Merge pull request #140 from ak--47/forward-value-on-error
Browse files Browse the repository at this point in the history
Forward value on error
  • Loading branch information
uhop committed May 4, 2024
2 parents 2c0ec73 + 739b38e commit 9c4abd6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jsonl/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class JsonlParser extends Utf8Stream {
try {
return JSON.parse(input, reviver);
} catch (error) {
if (typeof errorIndicator == 'function') return errorIndicator(error);
if (typeof errorIndicator == 'function') return errorIndicator(error, input, reviver);
}
return errorIndicator;
}
Expand Down
18 changes: 18 additions & 0 deletions tests/test_jsonl.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,24 @@ unit.add(module, [
async.done();
});

readString('{\n1\n]\n2\n3').pipe(stream);
},
function test_jsonl_transform_errors_forward(t) {
const async = t.startAsync('test_jsonl_transform_errors_forward');

const stream = parser({errorIndicator: (e, val) => val}),
result = [];

stream.on('data', data => result.push(data));
stream.on('error', err => {
eval(t.TEST("!'We shouldn't be here.'"));
async.done();
});
stream.on('end', value => {
eval(t.TEST("t.unify(result, [{key: 0, value: '{'}, {key: 1, value: 1}, {key: 2, value: ']'}, {key: 3, value: 2}, {key:4, value: 3}])"));
async.done();
});

readString('{\n1\n]\n2\n3').pipe(stream);
}
]);

0 comments on commit 9c4abd6

Please sign in to comment.