Skip to content

Commit 9e7a038

Browse files
committed
feat: batchExec supports error callback
1 parent 7efeea1 commit 9e7a038

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jsonpath-rfc9535",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "A JSONPath implementation based on RFC 9535",
55
"keywords": [
66
"json",

src/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,22 @@ export function exec(input: JsonValue, expression: string, cb: Callback): void {
3030
export function batchExec(
3131
input: JsonValue,
3232
expressionToCallback: Map<string, Callback>,
33+
errorCallback?: ErrorCallback,
3334
): void {
3435
for (const [expression, cb] of expressionToCallback) {
35-
exec(input, expression, cb);
36+
try {
37+
exec(input, expression, cb);
38+
} catch (e) {
39+
errorCallback?.(
40+
e instanceof Error ? e : new Error(String(e)),
41+
expression,
42+
);
43+
}
3644
}
3745
}
3846

3947
export type { JsonValue };
4048

49+
export type ErrorCallback = (error: Error, expression: string) => void;
4150
export type { Callback } from "./core/types.ts";
4251
export type { Path } from "./core/path.ts";

0 commit comments

Comments
 (0)