traces to bottom

This commit is contained in:
Ben Burdette 2020-06-23 09:36:58 -06:00
parent 54e8f550c9
commit 13e87535ff

View file

@ -284,21 +284,20 @@ std::ostream& operator<<(std::ostream &out, const ErrorInfo &einfo)
if (einfo.nixCode.has_value()) { if (einfo.nixCode.has_value()) {
switch (einfo.nixCode->errPos.origin) { switch (einfo.nixCode->errPos.origin) {
case foFile: { 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; 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; break;
} }
case foString: { case foString: {
out << fmt("%1%from command line argument %2%", prefix, showErrPos(einfo.nixCode->errPos)) << std::endl;
out << prefix << std::endl; out << prefix << std::endl;
out << fmt("%1%from command line argument %2%", prefix, showErrPos(einfo.nixCode->errPos)) << std::endl;
break; break;
} }
case foStdin: { case foStdin: {
out << fmt("%1%from stdin %2%", prefix, showErrPos(einfo.nixCode->errPos)) << std::endl;
out << prefix << std::endl; out << prefix << std::endl;
out << fmt("%1%from stdin %2%", prefix, showErrPos(einfo.nixCode->errPos)) << std::endl;
break; break;
} }
default: default:
@ -307,22 +306,6 @@ std::ostream& operator<<(std::ostream &out, const ErrorInfo &einfo)
nl = true; 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 // description
if (einfo.description != "") { if (einfo.description != "") {
if (nl) if (nl)
@ -352,6 +335,26 @@ std::ostream& operator<<(std::ostream &out, const ErrorInfo &einfo)
nl = true; 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; return out;
} }
} }