diff options
author | Shay Bergmann <shaybergmann@gmail.com> | 2021-10-27 19:48:48 +0000 |
---|---|---|
committer | Shay Bergmann <shaybergmann@gmail.com> | 2021-10-27 19:48:48 +0000 |
commit | a50c027ece2dc853109c7d2c2f10dd6581e2554d (patch) | |
tree | c60d7cc026d812ceeb18ba13f655e407af91e921 | |
parent | 465a167c4347cd208f39670bad349fc61bb42d3d (diff) |
toJSON: improve pos accuracy, add trace
-rw-r--r-- | src/libexpr/value-to-json.cc | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/libexpr/value-to-json.cc b/src/libexpr/value-to-json.cc index 1c3849593..4d642c720 100644 --- a/src/libexpr/value-to-json.cc +++ b/src/libexpr/value-to-json.cc @@ -40,7 +40,7 @@ void printValueAsJSON(EvalState & state, bool strict, break; case nAttrs: { - auto maybeString = state.tryAttrsToString(noPos, v, context, false, false); + auto maybeString = state.tryAttrsToString(pos, v, context, false, false); if (maybeString) { out.write(*maybeString); break; @@ -79,16 +79,12 @@ void printValueAsJSON(EvalState & state, bool strict, break; case nThunk: - throw TypeError({ - .msg = hintfmt("cannot convert %1% to JSON", showType(v)), - .errPos = pos - }); - case nFunction: - throw TypeError({ + auto e = TypeError({ .msg = hintfmt("cannot convert %1% to JSON", showType(v)), - .errPos = pos + .errPos = v.determinePos(pos) }); + throw e.addTrace(pos, hintfmt("message for the trace")); } } |