From 023912def37c8db64dec0339d39f2535e0d79e78 Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Wed, 24 Jun 2020 13:46:25 -0600 Subject: [PATCH] convenience form of addTrace --- src/libexpr/eval.cc | 6 +++--- src/libexpr/primops.cc | 12 ++++++------ src/libutil/error.hh | 6 ++++++ src/nix-env/nix-env.cc | 4 ++-- src/nix/search.cc | 2 +- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 3fd8aa285..1cbbb7ade 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -594,17 +594,17 @@ LocalNoInlineNoReturn(void throwUndefinedVarError(const Pos & pos, const char * LocalNoInline(void addErrorTrace(Error & e, const char * s, const string & s2)) { - e.addTrace(std::nullopt, hintfmt(s) % s2); + e.addTrace(std::nullopt, s, s2); } LocalNoInline(void addErrorTrace(Error & e, const Pos & pos, const char * s, const ExprLambda & fun)) { - e.addTrace(pos, hintfmt(s) % fun.showNamePos()); + e.addTrace(pos, s, fun.showNamePos()); } LocalNoInline(void addErrorTrace(Error & e, const Pos & pos, const char * s, const string & s2)) { - e.addTrace(pos, hintfmt(s) % s2); + e.addTrace(pos, s, s2); } diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 6f7a691cd..4cc3718e3 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -239,13 +239,13 @@ void prim_exec(EvalState & state, const Pos & pos, Value * * args, Value & v) try { parsed = state.parseExprFromString(output, pos.file); } catch (Error & e) { - e.addTrace(pos, hintfmt("While parsing the output from '%1%'", program)); + e.addTrace(pos, "While parsing the output from '%1%'", program); throw; } try { state.eval(parsed, v); } catch (Error & e) { - e.addTrace(pos, hintfmt("While evaluating the output from '%1%'", program)); + e.addTrace(pos, "While evaluating the output from '%1%'", program); throw; } } @@ -472,7 +472,7 @@ static void prim_addErrorContext(EvalState & state, const Pos & pos, Value * * a } catch (Error & e) { PathSet context; // TODO: is this right, include this pos?? Test it. esp with LOC. - e.addTrace(pos, hintfmt("%1%") % state.coerceToString(pos, *args[0], context)); + e.addTrace(pos, "%1%", state.coerceToString(pos, *args[0], context)); throw; } } @@ -564,7 +564,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * * try { drvName = state.forceStringNoCtx(*attr->value, pos); } catch (Error & e) { - e.addTrace(posDrvName, hintfmt("while evaluating the derivation attribute 'name'")); + e.addTrace(posDrvName, "while evaluating the derivation attribute 'name'"); throw; } @@ -698,8 +698,8 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * * } catch (Error & e) { e.addTrace(posDrvName, - hintfmt("while evaluating the attribute '%1%' of the derivation '%2%'", - key, drvName)); + "while evaluating the attribute '%1%' of the derivation '%2%'", + key, drvName); throw; } } diff --git a/src/libutil/error.hh b/src/libutil/error.hh index 3879d9b5f..09fc57fee 100644 --- a/src/libutil/error.hh +++ b/src/libutil/error.hh @@ -166,6 +166,12 @@ public: const string & msg() const { return calcWhat(); } const ErrorInfo & info() { calcWhat(); return err; } + template + BaseError & addTrace(std::optional e, const string &fs, const Args & ... args) + { + return addTrace(e, hintfmt(fs, args...)); + } + BaseError & addTrace(std::optional e, hintformat hint); }; diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index f5dfbf9f6..c992b7d74 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -593,7 +593,7 @@ static void upgradeDerivations(Globals & globals, } else newElems.push_back(i); } catch (Error & e) { - e.addTrace(std::nullopt, hintfmt("while trying to find an upgrade for '%s'", i.queryName())); + e.addTrace(std::nullopt, "while trying to find an upgrade for '%s'", i.queryName()); throw; } } @@ -1185,7 +1185,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs) } catch (AssertionError & e) { printMsg(lvlTalkative, "skipping derivation named '%1%' which gives an assertion failure", i.queryName()); } catch (Error & e) { - e.addTrace(std::nullopt, hintfmt("while querying the derivation named '%1%'", i.queryName())); + e.addTrace(std::nullopt, "while querying the derivation named '%1%'", i.queryName()); throw; } } diff --git a/src/nix/search.cc b/src/nix/search.cc index d9c730796..93c3f3f83 100644 --- a/src/nix/search.cc +++ b/src/nix/search.cc @@ -216,7 +216,7 @@ struct CmdSearch : SourceExprCommand, MixJSON } catch (AssertionError & e) { } catch (Error & e) { if (!toplevel) { - e.addTrace(std::nullopt, hintfmt("While evaluating the attribute '%s'", attrPath)); + e.addTrace(std::nullopt, "While evaluating the attribute '%s'", attrPath); throw; } }