toJSON: improve pos accuracy, add trace

This commit is contained in:
Shay Bergmann 2021-10-27 19:48:48 +00:00
parent 465a167c43
commit a50c027ece
No known key found for this signature in database
GPG key ID: 4D33B73FFDB9217C

View file

@ -40,7 +40,7 @@ void printValueAsJSON(EvalState & state, bool strict,
break; break;
case nAttrs: { case nAttrs: {
auto maybeString = state.tryAttrsToString(noPos, v, context, false, false); auto maybeString = state.tryAttrsToString(pos, v, context, false, false);
if (maybeString) { if (maybeString) {
out.write(*maybeString); out.write(*maybeString);
break; break;
@ -79,16 +79,12 @@ void printValueAsJSON(EvalState & state, bool strict,
break; break;
case nThunk: case nThunk:
throw TypeError({
.msg = hintfmt("cannot convert %1% to JSON", showType(v)),
.errPos = pos
});
case nFunction: case nFunction:
throw TypeError({ auto e = TypeError({
.msg = hintfmt("cannot convert %1% to JSON", showType(v)), .msg = hintfmt("cannot convert %1% to JSON", showType(v)),
.errPos = pos .errPos = v.determinePos(pos)
}); });
throw e.addTrace(pos, hintfmt("message for the trace"));
} }
} }