#include "lix/libexpr/eval-error.hh" #include "lix/libexpr/eval.hh" #include "lix/libexpr/value.hh" namespace nix { template EvalErrorBuilder EvalErrorBuilder::withExitStatus(unsigned int exitStatus) && { error->withExitStatus(exitStatus); return std::move(*this); } template EvalErrorBuilder EvalErrorBuilder::atPos(PosIdx pos) && { error->err.pos = positions[pos]; return std::move(*this); } template EvalErrorBuilder EvalErrorBuilder::atPos(Value & value, PosIdx fallback) && { return std::move(*this).atPos(value.determinePos(fallback)); } template EvalErrorBuilder EvalErrorBuilder::withTrace(PosIdx pos, const std::string_view text) && { error->err.traces.push_front( Trace{.pos = positions[pos], .hint = HintFmt(std::string(text))}); return std::move(*this); } template EvalErrorBuilder EvalErrorBuilder::withSuggestions(Suggestions & s) && { error->err.suggestions = s; return std::move(*this); } template EvalErrorBuilder EvalErrorBuilder::withFrame(const Env & env, const Expr & expr) && { if (debug) { error->frame = debug->addTrace(DebugTrace{ .pos = positions[expr.getPos()], .expr = expr, .env = env, .hint = HintFmt("Fake frame for debugging purposes"), .isError = true }).entry; } return std::move(*this); } template EvalErrorBuilder EvalErrorBuilder::addTrace(PosIdx pos, HintFmt hint) && { error->addTrace(positions[pos], hint); return std::move(*this); } template template EvalErrorBuilder EvalErrorBuilder::addTrace(PosIdx pos, std::string_view formatString, const Args &... formatArgs) && { addTrace(positions[pos], HintFmt(std::string(formatString), formatArgs...)); return std::move(*this); } template void EvalErrorBuilder::debugThrow() && { if (debug) { if (auto last = debug->traces().next()) { const Env * env = &(*last)->env; const Expr * expr = &(*last)->expr; debug->onEvalError(error.get(), *env, *expr); } } throw *error; } template class EvalErrorBuilder; template class EvalErrorBuilder; template class EvalErrorBuilder; template class EvalErrorBuilder; template class EvalErrorBuilder; template class EvalErrorBuilder; template class EvalErrorBuilder; template class EvalErrorBuilder; template class EvalErrorBuilder; }