From 31ce52a045ac384b542f8409f20c0461ab6263ac Mon Sep 17 00:00:00 2001 From: Guillaume Maudoux Date: Thu, 20 Oct 2022 14:18:35 +0200 Subject: [PATCH] Fix context message being printed twice with forceStringNoCtx --- src/libexpr/eval.cc | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 050b49833..0febff022 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -2168,19 +2168,11 @@ std::string_view EvalState::forceString(Value & v, PathSet & context, const PosI std::string_view EvalState::forceStringNoCtx(Value & v, const PosIdx pos, std::string_view errorCtx) { - try { - auto s = forceString(v, pos, errorCtx); - if (v.string.context) { - if (pos) - throwError(noPos, "the string '%1%' is not allowed to refer to a store path (such as '%2%')", v.string.s, v.string.context[0], 0, 0, 0, 0, noPos, "", 0, 0, 0); - else - throwError(noPos, "the string '%1%' is not allowed to refer to a store path (such as '%2%')", v.string.s, v.string.context[0], 0, 0, 0, 0, noPos, "", 0, 0, 0); - } - return s; - } catch (Error & e) { - e.addTrace(positions[pos], errorCtx); - throw; + auto s = forceString(v, pos, errorCtx); + if (v.string.context) { + throwErrorWithTrace(noPos, "the string '%1%' is not allowed to refer to a store path (such as '%2%')", v.string.s, v.string.context[0], 0, 0, 0, 0, noPos, "", 0, pos, errorCtx, 0, 0); } + return s; }