From 91e89628fdfe7b08e0f61b8531edd31833330e04 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Thu, 22 Feb 2024 17:18:27 -0800 Subject: [PATCH] Make `addErrorTrace` variadic --- src/libexpr/eval.cc | 12 +++++++----- src/libexpr/eval.hh | 6 ++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 54b1125ce..c4e163b08 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -806,14 +806,16 @@ void EvalState::runDebugRepl(const Error * error, const Env & env, const Expr & } } -void EvalState::addErrorTrace(Error & e, const char * s, const std::string & s2) const +template +void EvalState::addErrorTrace(Error & e, const Args & ... formatArgs) const { - e.addTrace(nullptr, s, s2); + e.addTrace(nullptr, HintFmt(formatArgs...)); } -void EvalState::addErrorTrace(Error & e, const PosIdx pos, const char * s, const std::string & s2) const +template +void EvalState::addErrorTrace(Error & e, const PosIdx pos, const Args & ... formatArgs) const { - e.addTrace(positions[pos], HintFmt(s, s2)); + e.addTrace(positions[pos], HintFmt(formatArgs...)); } template @@ -1588,7 +1590,7 @@ void EvalState::callFunction(Value & fun, size_t nrArgs, Value * * args, Value & lambda.name ? concatStrings("'", symbols[lambda.name], "'") : "anonymous lambda"); - if (pos) addErrorTrace(e, pos, "from call site%s", ""); + if (pos) addErrorTrace(e, pos, "from call site"); } throw; } diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 80b583eb1..01abd4eb1 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -432,10 +432,12 @@ public: std::string_view forceString(Value & v, NixStringContext & context, const PosIdx pos, std::string_view errorCtx); std::string_view forceStringNoCtx(Value & v, const PosIdx pos, std::string_view errorCtx); + template [[gnu::noinline]] - void addErrorTrace(Error & e, const char * s, const std::string & s2) const; + void addErrorTrace(Error & e, const Args & ... formatArgs) const; + template [[gnu::noinline]] - void addErrorTrace(Error & e, const PosIdx pos, const char * s, const std::string & s2) const; + void addErrorTrace(Error & e, const PosIdx pos, const Args & ... formatArgs) const; public: /**