1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-26 15:51:15 +02:00

Refactor to use more traces and less string manipulations

This commit is contained in:
Guillaume Maudoux 2022-03-18 00:58:09 +01:00
parent 13c4dc6532
commit e6d07e0d89
8 changed files with 475 additions and 442 deletions

View file

@ -130,6 +130,8 @@ protected:
public:
unsigned int status = 1; // exit status
BaseError(const BaseError &) = default;
template<typename... Args>
BaseError(unsigned int status, const Args & ... args)
: err { .level = lvlError, .msg = hintfmt(args...) }
@ -165,10 +167,14 @@ public:
const std::string & msg() const { return calcWhat(); }
const ErrorInfo & info() const { calcWhat(); return err; }
void pushTrace(Trace trace) {
err.traces.push_front(trace);
}
template<typename... Args>
BaseError & addTrace(std::optional<ErrPos> e, const std::string & fs, const Args & ... args)
BaseError & addTrace(std::optional<ErrPos> e, const std::string_view & fs, const Args & ... args)
{
return addTrace(e, hintfmt(fs, args...));
return addTrace(e, hintfmt(std::string(fs), args...));
}
BaseError & addTrace(std::optional<ErrPos> e, hintformat hint);