From c3c068284276d8dbea7bfdd2439ee13e3cef8413 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 28 Sep 2022 17:01:16 +0200 Subject: [PATCH] Don't show "from call site" when we don't know the call site MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This gets rid of stack trace entries like … from call site at «stdin»:0: (source not available) --- src/libexpr/eval.cc | 3 ++- src/libexpr/nixexpr.hh | 6 +++++- src/libutil/error.cc | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index bfe6c01dd..08ec2fac4 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -1617,7 +1617,8 @@ void EvalState::callFunction(Value & fun, size_t nrArgs, Value * * args, Value & (lambda.name ? concatStrings("'", symbols[lambda.name], "'") : "anonymous lambda")); - addErrorTrace(e, pos, "from call site%s", ""); + if (pos != noPos) + addErrorTrace(e, pos, "from call site", ""); } throw; } diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index 281881543..efd238211 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -52,7 +52,11 @@ public: explicit operator bool() const { return id > 0; } - bool operator<(const PosIdx other) const { return id < other.id; } + bool operator <(const PosIdx other) const { return id < other.id; } + + bool operator ==(const PosIdx other) const { return id == other.id; } + + bool operator !=(const PosIdx other) const { return id != other.id; } }; class PosTable diff --git a/src/libutil/error.cc b/src/libutil/error.cc index fa825b2f6..f570dca1d 100644 --- a/src/libutil/error.cc +++ b/src/libutil/error.cc @@ -30,12 +30,12 @@ const std::string & BaseError::calcWhat() const std::optional ErrorInfo::programName = std::nullopt; -std::ostream & operator<<(std::ostream & os, const hintformat & hf) +std::ostream & operator <<(std::ostream & os, const hintformat & hf) { return os << hf.str(); } -std::ostream & operator << (std::ostream & str, const AbstractPos & pos) +std::ostream & operator <<(std::ostream & str, const AbstractPos & pos) { pos.print(str); str << ":" << pos.line;