diff --git a/src/libutil/error.cc b/src/libutil/error.cc index 0199ee5f8..02eb3f7cb 100644 --- a/src/libutil/error.cc +++ b/src/libutil/error.cc @@ -328,41 +328,48 @@ std::ostream& showErrorInfo(std::ostream &out, const ErrorInfo &einfo, bool show } // traces - if (showTrace) { + if (showTrace && !einfo.traces.empty()) + { + const string tracetitle(" show-trace output "); + + int fill = errwidth - tracetitle.length(); + int lw = 0; + int rw = 0; + const int min_dashes = 3; + if (fill > min_dashes * 2) { + if (fill % 2 != 0) { + lw = fill / 2; + rw = lw + 1; + } + else + { + lw = rw = fill / 2; + } + } + else + lw = rw = min_dashes; + + 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 { - if (nl) - out << std::endl << prefix; - - const string tracetitle(" show-trace output "); - - int fill = errwidth - tracetitle.length(); - int lw = 0; - int rw = 0; - const int min_dashes = 3; - if (fill > min_dashes * 2) { - if (fill % 2 != 0) { - lw = fill / 2; - rw = lw + 1; - } - else - { - lw = rw = fill / 2; - } - } - else - lw = rw = min_dashes; - - out << ANSI_BLUE << std::string(lw, '-') << tracetitle << std::string(rw, '-') << std::endl << prefix; - out << iter->hint.str() << std::endl; + 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; } diff --git a/src/nix/installables.cc b/src/nix/installables.cc index 166ba167f..708a0dc88 100644 --- a/src/nix/installables.cc +++ b/src/nix/installables.cc @@ -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> parseInstallables( - SourceExprCommand & cmd, ref store, std::vetor ss, bool useDefaultInstallables) + SourceExprCommand & cmd, ref store, std::vector ss, bool useDefaultInstallables) { std::vector> result;