mirror of
https://github.com/NixOS/nix
synced 2025-07-06 05:01:48 +02:00
Always print addErrorContext traces
This commit is contained in:
parent
38ba96d7b0
commit
bebacc475c
7 changed files with 90 additions and 17 deletions
|
@ -11,9 +11,9 @@
|
|||
|
||||
namespace nix {
|
||||
|
||||
void BaseError::addTrace(std::shared_ptr<Pos> && e, HintFmt hint)
|
||||
void BaseError::addTrace(std::shared_ptr<Pos> && e, HintFmt hint, TraceKind kind)
|
||||
{
|
||||
err.traces.push_front(Trace { .pos = std::move(e), .hint = hint });
|
||||
err.traces.push_front(Trace { .pos = std::move(e), .hint = hint, .kind = kind });
|
||||
}
|
||||
|
||||
void throwExceptionSelfCheck(){
|
||||
|
@ -379,29 +379,39 @@ std::ostream & showErrorInfo(std::ostream & out, const ErrorInfo & einfo, bool s
|
|||
// A consecutive sequence of stack traces that are all in `tracesSeen`.
|
||||
std::vector<Trace> skippedTraces;
|
||||
size_t count = 0;
|
||||
bool truncate = false;
|
||||
|
||||
for (const auto & trace : einfo.traces) {
|
||||
if (trace.hint.str().empty()) continue;
|
||||
|
||||
if (!showTrace && count > 3) {
|
||||
oss << "\n" << ANSI_WARNING "(stack trace truncated; use '--show-trace' to show the full trace)" ANSI_NORMAL << "\n";
|
||||
break;
|
||||
truncate = true;
|
||||
}
|
||||
|
||||
if (tracesSeen.count(trace)) {
|
||||
skippedTraces.push_back(trace);
|
||||
continue;
|
||||
if (!truncate || trace.kind == TraceKind::Custom) {
|
||||
|
||||
if (tracesSeen.count(trace)) {
|
||||
skippedTraces.push_back(trace);
|
||||
continue;
|
||||
}
|
||||
|
||||
tracesSeen.insert(trace);
|
||||
|
||||
printSkippedTracesMaybe(oss, ellipsisIndent, count, skippedTraces, tracesSeen);
|
||||
|
||||
count++;
|
||||
|
||||
printTrace(oss, ellipsisIndent, count, trace);
|
||||
}
|
||||
tracesSeen.insert(trace);
|
||||
|
||||
printSkippedTracesMaybe(oss, ellipsisIndent, count, skippedTraces, tracesSeen);
|
||||
|
||||
count++;
|
||||
|
||||
printTrace(oss, ellipsisIndent, count, trace);
|
||||
}
|
||||
|
||||
|
||||
printSkippedTracesMaybe(oss, ellipsisIndent, count, skippedTraces, tracesSeen);
|
||||
|
||||
if (truncate) {
|
||||
oss << "\n" << ANSI_WARNING "(stack trace truncated; use '--show-trace' to show the full, detailed trace)" ANSI_NORMAL << "\n";
|
||||
}
|
||||
|
||||
oss << "\n" << prefix;
|
||||
}
|
||||
|
||||
|
|
|
@ -61,9 +61,16 @@ void printCodeLines(std::ostream & out,
|
|||
const Pos & errPos,
|
||||
const LinesOfCode & loc);
|
||||
|
||||
enum struct TraceKind {
|
||||
Other,
|
||||
/** Produced by builtins.addErrorContext. Always printed. */
|
||||
Custom,
|
||||
};
|
||||
|
||||
struct Trace {
|
||||
std::shared_ptr<Pos> pos;
|
||||
HintFmt hint;
|
||||
TraceKind kind = TraceKind::Other;
|
||||
};
|
||||
|
||||
inline bool operator<(const Trace& lhs, const Trace& rhs);
|
||||
|
@ -161,7 +168,7 @@ public:
|
|||
addTrace(std::move(e), HintFmt(std::string(fs), args...));
|
||||
}
|
||||
|
||||
void addTrace(std::shared_ptr<Pos> && e, HintFmt hint);
|
||||
void addTrace(std::shared_ptr<Pos> && e, HintFmt hint, TraceKind kind = TraceKind::Other);
|
||||
|
||||
bool hasTrace() const { return !err.traces.empty(); }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue