trace formatting

This commit is contained in:
Ben Burdette 2020-06-29 15:46:21 -06:00
parent 8f81fae116
commit c484a67914
2 changed files with 33 additions and 26 deletions

View file

@ -328,13 +328,8 @@ std::ostream& showErrorInfo(std::ostream &out, const ErrorInfo &einfo, bool show
}
// traces
if (showTrace) {
for (auto iter = einfo.traces.rbegin(); iter != einfo.traces.rend(); ++iter)
if (showTrace && !einfo.traces.empty())
{
try {
if (nl)
out << std::endl << prefix;
const string tracetitle(" show-trace output ");
int fill = errwidth - tracetitle.length();
@ -354,15 +349,27 @@ std::ostream& showErrorInfo(std::ostream &out, const ErrorInfo &einfo, bool show
else
lw = rw = min_dashes;
out << ANSI_BLUE << std::string(lw, '-') << tracetitle << std::string(rw, '-') << std::endl << prefix;
out << iter->hint.str() << std::endl;
if (nl)
out << std::endl << prefix;
out << ANSI_BLUE << std::string(lw, '-') << tracetitle << std::string(rw, '-') << ANSI_NORMAL;
for (auto iter = einfo.traces.rbegin(); iter != einfo.traces.rend(); ++iter)
{
try {
out << std::endl << prefix;
out << ANSI_BLUE << "trace: " << ANSI_NORMAL << iter->hint.str() << std::endl;
auto pos = *iter->pos;
printAtPos(prefix, pos, out);
nl = true;
auto loc = getCodeLines(pos);
if (loc.has_value())
{
out << std::endl;
printCodeLines(out, prefix, pos, *loc);
out << std::endl;
}
} catch(const std::bad_optional_access& e) {
out << iter->hint.str() << std::endl;
}

View file

@ -212,7 +212,7 @@ std::string attrRegex = R"([A-Za-z_][A-Za-z0-9-_+]*)";
static std::regex attrPathRegex(fmt(R"(%1%(\.%1%)*)", attrRegex));
static std::vector<std::shared_ptr<Installable>> parseInstallables(
SourceExprCommand & cmd, ref<Store> store, std::vetor<std::string> ss, bool useDefaultInstallables)
SourceExprCommand & cmd, ref<Store> store, std::vector<std::string> ss, bool useDefaultInstallables)
{
std::vector<std::shared_ptr<Installable>> result;