Skip to content

Commit 8d464a4

Browse files
committed
Fix error position property set for errors in functions
1 parent b97c9d7 commit 8d464a4

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/jsonata.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,7 @@ var jsonata = (function() {
14121412
throw {
14131413
code: "T1005",
14141414
stack: (new Error()).stack,
1415-
position: expr.position,
1415+
position: expr.position - 1,
14161416
token: expr.procedure.steps[0].value
14171417
};
14181418
}
@@ -1447,7 +1447,7 @@ var jsonata = (function() {
14471447
} catch (err) {
14481448
if(!err.position) {
14491449
// add the position field to the error
1450-
err.position = expr.position;
1450+
err.position = expr.position - 1;
14511451
}
14521452
if (!err.token) {
14531453
// and the function identifier
@@ -1539,7 +1539,7 @@ var jsonata = (function() {
15391539
if (typeof err.token == 'undefined' && typeof proc.token !== 'undefined') {
15401540
err.token = proc.token;
15411541
}
1542-
err.position = proc.position;
1542+
err.position = proc.position - 1;
15431543
}
15441544
throw err;
15451545
}

test/implementation-tests.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ describe("Tests that bind Javascript functions", () => {
347347
expr.evaluate({});
348348
})
349349
.to.throw(DOMException)
350-
.to.deep.contain({ message: 'Here is my message', position: 12, token: 'throwDomEx' });
350+
.to.deep.contain({ message: 'Here is my message', position: 11, token: 'throwDomEx' });
351351
});
352352
});
353353

@@ -557,7 +557,7 @@ describe("Tests that bind Javascript functions", () => {
557557
var result = expr.evaluate();
558558
var expected = [true, false];
559559
expect(result).to.deep.equal(expected);
560-
})
560+
});
561561

562562
});
563563
});
@@ -736,7 +736,7 @@ describe("Tests that are specific to a Javascript runtime", () => {
736736
expr.evaluate();
737737
})
738738
.to.throw()
739-
.to.deep.contain({ position: 7, code: "D3040", token: "match", index: 3, value: -3 });
739+
.to.deep.contain({ position: 6, code: "D3040", token: "match", index: 3, value: -3 });
740740
});
741741
});
742742

@@ -747,7 +747,7 @@ describe("Tests that are specific to a Javascript runtime", () => {
747747
expr.evaluate();
748748
})
749749
.to.throw()
750-
.to.deep.contain({ position: 7, code: "T0410", token: "match", index: 3, value: null });
750+
.to.deep.contain({ position: 6, code: "T0410", token: "match", index: 3, value: null });
751751
});
752752
});
753753

@@ -758,7 +758,7 @@ describe("Tests that are specific to a Javascript runtime", () => {
758758
expr.evaluate();
759759
})
760760
.to.throw()
761-
.to.deep.contain({ position: 7, code: "T0410", token: "match", index: 3, value: "2" });
761+
.to.deep.contain({ position: 6, code: "T0410", token: "match", index: 3, value: "2" });
762762
});
763763
});
764764

@@ -769,7 +769,7 @@ describe("Tests that are specific to a Javascript runtime", () => {
769769
expr.evaluate();
770770
})
771771
.to.throw()
772-
.to.deep.contain({ position: 7, code: "T0410", token: "match", index: 2, value: "ab" });
772+
.to.deep.contain({ position: 6, code: "T0410", token: "match", index: 2, value: "ab" });
773773
});
774774
});
775775

@@ -780,7 +780,7 @@ describe("Tests that are specific to a Javascript runtime", () => {
780780
expr.evaluate();
781781
})
782782
.to.throw()
783-
.to.deep.contain({ position: 7, code: "T0410", token: "match", index: 2, value: true });
783+
.to.deep.contain({ position: 6, code: "T0410", token: "match", index: 2, value: true });
784784
});
785785
});
786786

@@ -791,7 +791,7 @@ describe("Tests that are specific to a Javascript runtime", () => {
791791
expr.evaluate();
792792
})
793793
.to.throw()
794-
.to.deep.contain({ position: 7, code: "T0410", token: "match", index: 1, value: 12345 });
794+
.to.deep.contain({ position: 6, code: "T0410", token: "match", index: 1, value: 12345 });
795795
});
796796
});
797797

@@ -802,7 +802,7 @@ describe("Tests that are specific to a Javascript runtime", () => {
802802
expr.evaluate();
803803
})
804804
.to.throw()
805-
.to.deep.contain({ position: 7, code: "T0410", token: "match", index: 1 });
805+
.to.deep.contain({ position: 6, code: "T0410", token: "match", index: 1 });
806806
});
807807
});
808808
});
@@ -829,7 +829,7 @@ describe("Tests that include infinite recursion", () => {
829829
expr.evaluate();
830830
})
831831
.to.throw()
832-
.to.deep.contain({ token: "inf", position: 32, code: "U1001" });
832+
.to.deep.contain({ token: "inf", position: 31, code: "U1001" });
833833
});
834834
});
835835

0 commit comments

Comments
 (0)