convenience form of addTrace

This commit is contained in:
Ben Burdette 2020-06-24 13:46:25 -06:00
parent 93e9307329
commit 023912def3
5 changed files with 18 additions and 12 deletions

View file

@ -594,17 +594,17 @@ LocalNoInlineNoReturn(void throwUndefinedVarError(const Pos & pos, const char *
LocalNoInline(void addErrorTrace(Error & e, const char * s, const string & s2)) 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)) 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)) 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);
} }

View file

@ -239,13 +239,13 @@ void prim_exec(EvalState & state, const Pos & pos, Value * * args, Value & v)
try { try {
parsed = state.parseExprFromString(output, pos.file); parsed = state.parseExprFromString(output, pos.file);
} catch (Error & e) { } 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; throw;
} }
try { try {
state.eval(parsed, v); state.eval(parsed, v);
} catch (Error & e) { } 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; throw;
} }
} }
@ -472,7 +472,7 @@ static void prim_addErrorContext(EvalState & state, const Pos & pos, Value * * a
} catch (Error & e) { } catch (Error & e) {
PathSet context; PathSet context;
// TODO: is this right, include this pos?? Test it. esp with LOC. // 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; throw;
} }
} }
@ -564,7 +564,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
try { try {
drvName = state.forceStringNoCtx(*attr->value, pos); drvName = state.forceStringNoCtx(*attr->value, pos);
} catch (Error & e) { } catch (Error & e) {
e.addTrace(posDrvName, hintfmt("while evaluating the derivation attribute 'name'")); e.addTrace(posDrvName, "while evaluating the derivation attribute 'name'");
throw; throw;
} }
@ -698,8 +698,8 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
} catch (Error & e) { } catch (Error & e) {
e.addTrace(posDrvName, e.addTrace(posDrvName,
hintfmt("while evaluating the attribute '%1%' of the derivation '%2%'", "while evaluating the attribute '%1%' of the derivation '%2%'",
key, drvName)); key, drvName);
throw; throw;
} }
} }

View file

@ -166,6 +166,12 @@ public:
const string & msg() const { return calcWhat(); } const string & msg() const { return calcWhat(); }
const ErrorInfo & info() { calcWhat(); return err; } const ErrorInfo & info() { calcWhat(); return err; }
template<typename... Args>
BaseError & addTrace(std::optional<ErrPos> e, const string &fs, const Args & ... args)
{
return addTrace(e, hintfmt(fs, args...));
}
BaseError & addTrace(std::optional<ErrPos> e, hintformat hint); BaseError & addTrace(std::optional<ErrPos> e, hintformat hint);
}; };

View file

@ -593,7 +593,7 @@ static void upgradeDerivations(Globals & globals,
} else newElems.push_back(i); } else newElems.push_back(i);
} catch (Error & e) { } 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; throw;
} }
} }
@ -1185,7 +1185,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
} catch (AssertionError & e) { } catch (AssertionError & e) {
printMsg(lvlTalkative, "skipping derivation named '%1%' which gives an assertion failure", i.queryName()); printMsg(lvlTalkative, "skipping derivation named '%1%' which gives an assertion failure", i.queryName());
} catch (Error & e) { } 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; throw;
} }
} }

View file

@ -216,7 +216,7 @@ struct CmdSearch : SourceExprCommand, MixJSON
} catch (AssertionError & e) { } catch (AssertionError & e) {
} catch (Error & e) { } catch (Error & e) {
if (!toplevel) { if (!toplevel) {
e.addTrace(std::nullopt, hintfmt("While evaluating the attribute '%s'", attrPath)); e.addTrace(std::nullopt, "While evaluating the attribute '%s'", attrPath);
throw; throw;
} }
} }