primops/fromJSON: add error position in case of parse error

This makes it easier to track down where invalid JSON was passed to
`builtins.fromJSON`.
This commit is contained in:
Maximilian Bosch 2020-12-11 16:31:14 +01:00
parent c6a1bcd0ec
commit f890830b33
No known key found for this signature in database
GPG key ID: 091DBF4D1FC46B8E

View file

@ -1621,7 +1621,12 @@ static RegisterPrimOp primop_toJSON({
static void prim_fromJSON(EvalState & state, const Pos & pos, Value * * args, Value & v)
{
string s = state.forceStringNoCtx(*args[0], pos);
try {
parseJSON(state, s, v);
} catch (JSONParseError &e) {
e.addTrace(pos, "while decoding a JSON string");
throw e;
}
}
static RegisterPrimOp primop_fromJSON({