Skip to content

Commit

Permalink
primops/fromJSON: add error position in case of parse error
Browse files Browse the repository at this point in the history
This makes it easier to track down where invalid JSON was passed to
`builtins.fromJSON`.
  • Loading branch information
Ma27 committed Dec 11, 2020
1 parent c6a1bcd commit 4aa83e9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1621,7 +1621,13 @@ static RegisterPrimOp primop_toJSON({
static void prim_fromJSON(EvalState & state, const Pos & pos, Value * * args, Value & v)
{
string s = state.forceStringNoCtx(*args[0], pos);
parseJSON(state, s, v);
try {
parseJSON(state, s, v);
} catch (JSONParseError &e) {
auto info = e.info();
info.errPos = pos;
throw EvalError(info);
}
}

static RegisterPrimOp primop_fromJSON({
Expand Down

0 comments on commit 4aa83e9

Please sign in to comment.