libutil: Change return value of addTrace to void

The return value of BaseError::addTrace(...) is never used and
error-prone as subclasses calling it will return a BaseError instead of
the subclass.
This commit changes its return value to be void.
This commit is contained in:
Daniel Pauls 2022-03-30 17:30:47 +02:00
parent fa83b865a2
commit 629edd43ba
2 changed files with 4 additions and 5 deletions

View file

@ -9,10 +9,9 @@ namespace nix {
const std::string nativeSystem = SYSTEM; const std::string nativeSystem = SYSTEM;
BaseError & BaseError::addTrace(std::optional<ErrPos> e, hintformat hint) void BaseError::addTrace(std::optional<ErrPos> e, hintformat hint)
{ {
err.traces.push_front(Trace { .pos = e, .hint = hint }); err.traces.push_front(Trace { .pos = e, .hint = hint });
return *this;
} }
// c++ std::exception descendants must have a 'const char* what()' function. // c++ std::exception descendants must have a 'const char* what()' function.

View file

@ -175,12 +175,12 @@ public:
const ErrorInfo & info() const { calcWhat(); return err; } const ErrorInfo & info() const { calcWhat(); return err; }
template<typename... Args> template<typename... Args>
BaseError & addTrace(std::optional<ErrPos> e, const std::string & fs, const Args & ... args) void addTrace(std::optional<ErrPos> e, const std::string & fs, const Args & ... args)
{ {
return addTrace(e, hintfmt(fs, args...)); addTrace(e, hintfmt(fs, args...));
} }
BaseError & addTrace(std::optional<ErrPos> e, hintformat hint); void addTrace(std::optional<ErrPos> e, hintformat hint);
bool hasTrace() const { return !err.traces.empty(); } bool hasTrace() const { return !err.traces.empty(); }
}; };