toJSON: improve pos accuracy, add trace
This commit is contained in:
parent
465a167c43
commit
a50c027ece
1 changed files with 4 additions and 8 deletions
|
@ -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"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue