aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/error.cc
diff options
context:
space:
mode:
authorFlorian Friesdorf <florian@ternaris.com>2022-11-22 16:45:58 +0000
committerFlorian Friesdorf <florian@ternaris.com>2022-12-12 18:41:00 +0000
commitd269976be6def2928e6a315ab2b85b947f4308f2 (patch)
treeb50e51c05cb2736c79a821661f7654dc3ab8ed93 /src/libutil/error.cc
parent173dcb0af9249487c2d9ad5de7218fcf203873bd (diff)
Show stack trace above error message
Save developers from scrolling by displaying the error message last, below the stack trace.
Diffstat (limited to 'src/libutil/error.cc')
-rw-r--r--src/libutil/error.cc42
1 files changed, 22 insertions, 20 deletions
diff --git a/src/libutil/error.cc b/src/libutil/error.cc
index 9cac6ac91..449baaad1 100644
--- a/src/libutil/error.cc
+++ b/src/libutil/error.cc
@@ -262,6 +262,28 @@ std::ostream & showErrorInfo(std::ostream & out, const ErrorInfo & einfo, bool s
prefix += ":" ANSI_NORMAL " ";
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";
if (einfo.errPos.has_value() && *einfo.errPos) {
@@ -285,26 +307,6 @@ std::ostream & showErrorInfo(std::ostream & out, const ErrorInfo & einfo, bool s
"?" << 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()));
return out;