Skip to content

Commit

Permalink
Make addErrorTrace variadic
Browse files Browse the repository at this point in the history
  • Loading branch information
9999years committed Feb 23, 2024
1 parent f05c13e commit 91e8962
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename... Args>
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<typename... Args>
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<typename... Args>
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions src/libexpr/eval.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename... Args>
[[gnu::noinline]]
void addErrorTrace(Error & e, const char * s, const std::string & s2) const;
void addErrorTrace(Error & e, const Args & ... formatArgs) const;
template<typename... Args>
[[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:
/**
Expand Down

0 comments on commit 91e8962

Please sign in to comment.