Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error position property for errors in functions #570

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/jsonata.js
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@ var jsonata = (function() {
throw {
code: "T1005",
stack: (new Error()).stack,
position: expr.position,
position: expr.position - 1,
token: expr.procedure.steps[0].value
};
}
Expand Down Expand Up @@ -1447,7 +1447,7 @@ var jsonata = (function() {
} catch (err) {
if(!err.position) {
// add the position field to the error
err.position = expr.position;
err.position = expr.position - 1;
}
if (!err.token) {
// and the function identifier
Expand Down Expand Up @@ -1539,7 +1539,7 @@ var jsonata = (function() {
if (typeof err.token == 'undefined' && typeof proc.token !== 'undefined') {
err.token = proc.token;
}
err.position = proc.position;
err.position = proc.position - 1;
}
throw err;
}
Expand Down
20 changes: 10 additions & 10 deletions test/implementation-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ describe("Tests that bind Javascript functions", () => {
expr.evaluate({});
})
.to.throw(DOMException)
.to.deep.contain({ message: 'Here is my message', position: 12, token: 'throwDomEx' });
.to.deep.contain({ message: 'Here is my message', position: 11, token: 'throwDomEx' });
});
});

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

});
});
Expand Down Expand Up @@ -736,7 +736,7 @@ describe("Tests that are specific to a Javascript runtime", () => {
expr.evaluate();
})
.to.throw()
.to.deep.contain({ position: 7, code: "D3040", token: "match", index: 3, value: -3 });
.to.deep.contain({ position: 6, code: "D3040", token: "match", index: 3, value: -3 });
});
});

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

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

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

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

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

Expand All @@ -802,7 +802,7 @@ describe("Tests that are specific to a Javascript runtime", () => {
expr.evaluate();
})
.to.throw()
.to.deep.contain({ position: 7, code: "T0410", token: "match", index: 1 });
.to.deep.contain({ position: 6, code: "T0410", token: "match", index: 1 });
});
});
});
Expand All @@ -829,7 +829,7 @@ describe("Tests that include infinite recursion", () => {
expr.evaluate();
})
.to.throw()
.to.deep.contain({ token: "inf", position: 32, code: "U1001" });
.to.deep.contain({ token: "inf", position: 31, code: "U1001" });
});
});

Expand Down