forked from lix-project/lix
Merge pull request #7334 from chaoflow/stack-trace-order
Show stack trace above error message with innermost first
This commit is contained in:
commit
edb54c62e6
|
@ -1660,7 +1660,7 @@ void EvalState::callFunction(Value & fun, size_t nrArgs, Value * * args, Value &
|
||||||
(lambda.name
|
(lambda.name
|
||||||
? concatStrings("'", symbols[lambda.name], "'")
|
? concatStrings("'", symbols[lambda.name], "'")
|
||||||
: "anonymous lambda"));
|
: "anonymous lambda"));
|
||||||
addErrorTrace(e, pos, "from call site%s", "");
|
addErrorTrace(e, pos, "while evaluating call site%s", "");
|
||||||
}
|
}
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,7 +143,7 @@ static FlakeInput parseFlakeInput(EvalState & state,
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
e.addTrace(
|
e.addTrace(
|
||||||
state.positions[attr.pos],
|
state.positions[attr.pos],
|
||||||
hintfmt("in flake attribute '%s'", state.symbols[attr.name]));
|
hintfmt("while evaluating flake attribute '%s'", state.symbols[attr.name]));
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,7 @@ static FlakeInput parseFlakeInput(EvalState & state,
|
||||||
try {
|
try {
|
||||||
input.ref = FlakeRef::fromAttrs(attrs);
|
input.ref = FlakeRef::fromAttrs(attrs);
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
e.addTrace(state.positions[pos], hintfmt("in flake input"));
|
e.addTrace(state.positions[pos], hintfmt("while evaluating flake input"));
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -262,6 +262,28 @@ std::ostream & showErrorInfo(std::ostream & out, const ErrorInfo & einfo, bool s
|
||||||
prefix += ":" ANSI_NORMAL " ";
|
prefix += ":" ANSI_NORMAL " ";
|
||||||
|
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
|
|
||||||
|
// traces
|
||||||
|
if (showTrace && !einfo.traces.empty()) {
|
||||||
|
for (const auto & trace : einfo.traces) {
|
||||||
|
oss << "\n" << "… " << trace.hint.str() << "\n";
|
||||||
|
|
||||||
|
if (trace.pos.has_value() && (*trace.pos)) {
|
||||||
|
auto pos = trace.pos.value();
|
||||||
|
oss << "\n";
|
||||||
|
printAtPos(pos, oss);
|
||||||
|
|
||||||
|
auto loc = getCodeLines(pos);
|
||||||
|
if (loc.has_value()) {
|
||||||
|
oss << "\n";
|
||||||
|
printCodeLines(oss, "", pos, *loc);
|
||||||
|
oss << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
oss << "\n" << prefix;
|
||||||
|
}
|
||||||
|
|
||||||
oss << einfo.msg << "\n";
|
oss << einfo.msg << "\n";
|
||||||
|
|
||||||
if (einfo.errPos.has_value() && *einfo.errPos) {
|
if (einfo.errPos.has_value() && *einfo.errPos) {
|
||||||
|
@ -285,26 +307,6 @@ std::ostream & showErrorInfo(std::ostream & out, const ErrorInfo & einfo, bool s
|
||||||
"?" << std::endl;
|
"?" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// traces
|
|
||||||
if (showTrace && !einfo.traces.empty()) {
|
|
||||||
for (auto iter = einfo.traces.rbegin(); iter != einfo.traces.rend(); ++iter) {
|
|
||||||
oss << "\n" << "… " << iter->hint.str() << "\n";
|
|
||||||
|
|
||||||
if (iter->pos.has_value() && (*iter->pos)) {
|
|
||||||
auto pos = iter->pos.value();
|
|
||||||
oss << "\n";
|
|
||||||
printAtPos(pos, oss);
|
|
||||||
|
|
||||||
auto loc = getCodeLines(pos);
|
|
||||||
if (loc.has_value()) {
|
|
||||||
oss << "\n";
|
|
||||||
printCodeLines(oss, "", pos, *loc);
|
|
||||||
oss << "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
out << indent(prefix, std::string(filterANSIEscapes(prefix, true).size(), ' '), chomp(oss.str()));
|
out << indent(prefix, std::string(filterANSIEscapes(prefix, true).size(), ' '), chomp(oss.str()));
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
|
|
Loading…
Reference in a new issue