diff options
author | Guillaume Maudoux <guillaume.maudoux@tweag.io> | 2022-03-18 00:58:09 +0100 |
---|---|---|
committer | Guillaume Maudoux <guillaume.maudoux@tweag.io> | 2022-03-18 00:58:09 +0100 |
commit | e6d07e0d89d964cde22894fca57a95177c085c8d (patch) | |
tree | 90d2d64ea4f2796aadce2853ed4da31e0d46b047 /src/libutil/error.hh | |
parent | 13c4dc65327c9654c47e6d80c0f4e1797b999f97 (diff) |
Refactor to use more traces and less string manipulations
Diffstat (limited to 'src/libutil/error.hh')
-rw-r--r-- | src/libutil/error.hh | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/libutil/error.hh b/src/libutil/error.hh index d55e1d701..ad29f8d2a 100644 --- a/src/libutil/error.hh +++ b/src/libutil/error.hh @@ -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); |