From a50c027ece2dc853109c7d2c2f10dd6581e2554d Mon Sep 17 00:00:00 2001 From: Shay Bergmann Date: Wed, 27 Oct 2021 19:48:48 +0000 Subject: [PATCH] toJSON: improve pos accuracy, add trace --- src/libexpr/value-to-json.cc | 12 ++++-------- 1 file 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")); } }