Show stack trace above error message

Save developers from scrolling by displaying the error message last,
below the stack trace.
This commit is contained in:
Florian Friesdorf 2022-11-22 16:45:58 +00:00
parent 173dcb0af9
commit d269976be6

View file

@ -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 (auto iter = einfo.traces.begin(); iter != einfo.traces.end(); ++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";
}
}
}
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.begin(); iter != einfo.traces.end(); ++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;