diff options
-rw-r--r-- | src/libutil/error.cc | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/src/libutil/error.cc b/src/libutil/error.cc index 222d9cbef..a0dfdbdbd 100644 --- a/src/libutil/error.cc +++ b/src/libutil/error.cc @@ -284,21 +284,20 @@ std::ostream& operator<<(std::ostream &out, const ErrorInfo &einfo) if (einfo.nixCode.has_value()) { switch (einfo.nixCode->errPos.origin) { case foFile: { - out << fmt("%1%in file: " ANSI_BLUE "%2% %3%" ANSI_NORMAL, - prefix, - einfo.nixCode->errPos.file, - showErrPos(einfo.nixCode->errPos)) << std::endl; out << prefix << std::endl; + auto &pos = einfo.nixCode->errPos; + out << ANSI_BLUE << "at: " << ANSI_YELLOW << showErrPos(pos) << + ANSI_BLUE << " in file: " << ANSI_NORMAL << pos.file << std::endl; break; } case foString: { - out << fmt("%1%from command line argument %2%", prefix, showErrPos(einfo.nixCode->errPos)) << std::endl; out << prefix << std::endl; + out << fmt("%1%from command line argument %2%", prefix, showErrPos(einfo.nixCode->errPos)) << std::endl; break; } case foStdin: { - out << fmt("%1%from stdin %2%", prefix, showErrPos(einfo.nixCode->errPos)) << std::endl; out << prefix << std::endl; + out << fmt("%1%from stdin %2%", prefix, showErrPos(einfo.nixCode->errPos)) << std::endl; break; } default: @@ -307,22 +306,6 @@ std::ostream& operator<<(std::ostream &out, const ErrorInfo &einfo) nl = true; } - // traces - for (auto iter = einfo.traces.begin(); iter != einfo.traces.end(); ++iter) - { - - try { - auto pos = *iter->pos; - out << iter->hint.str() << showErrPos(pos) << std::endl; - NixCode nc { .errPos = pos }; - getCodeLines(nc); - printCodeLines(out, prefix, nc); - } catch(const std::bad_optional_access& e) { - out << iter->hint.str() << std::endl; - } - - } - // description if (einfo.description != "") { if (nl) @@ -352,6 +335,26 @@ std::ostream& operator<<(std::ostream &out, const ErrorInfo &einfo) nl = true; } + // traces + for (auto iter = einfo.traces.rbegin(); iter != einfo.traces.rend(); ++iter) + { + try { + auto pos = *iter->pos; + if (nl) + out << std::endl << prefix; + out << std::endl << prefix; + out << iter->hint.str() << std::endl; + out << ANSI_BLUE << "at: " << ANSI_YELLOW << showErrPos(pos) << + ANSI_BLUE << " in file: " << ANSI_NORMAL << pos.file << std::endl; + nl = true; + NixCode nc { .errPos = pos }; + getCodeLines(nc); + printCodeLines(out, prefix, nc); + } catch(const std::bad_optional_access& e) { + out << iter->hint.str() << std::endl; + } + } + return out; } } |