diff options
author | Guillaume Maudoux <guillaume.maudoux@tweag.io> | 2023-01-19 13:23:04 +0100 |
---|---|---|
committer | Guillaume Maudoux <guillaume.maudoux@tweag.io> | 2023-01-19 13:23:04 +0100 |
commit | e4726a0c797a2680b9149015dc5e6c1a922fc686 (patch) | |
tree | a5f4e60c2761932d3e40b789f9875706446ead6f /src/libutil/error.hh | |
parent | 38b90c618f5ce4334b89c0124c5a54f339a23db6 (diff) |
Revert "Revert "Merge pull request #6204 from layus/coerce-string""
This reverts commit 9b33ef3879a764bed4cc2404a08344c3a697a646.
Diffstat (limited to 'src/libutil/error.hh')
-rw-r--r-- | src/libutil/error.hh | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/libutil/error.hh b/src/libutil/error.hh index c3bb8c0df..7d236028c 100644 --- a/src/libutil/error.hh +++ b/src/libutil/error.hh @@ -86,6 +86,7 @@ void printCodeLines(std::ostream & out, struct Trace { std::shared_ptr<AbstractPos> pos; hintformat hint; + bool frame; }; struct ErrorInfo { @@ -114,6 +115,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...) } @@ -152,15 +155,22 @@ 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> - void addTrace(std::shared_ptr<AbstractPos> && e, const std::string & fs, const Args & ... args) + void addTrace(std::shared_ptr<AbstractPos> && e, std::string_view fs, const Args & ... args) { - addTrace(std::move(e), hintfmt(fs, args...)); + addTrace(std::move(e), hintfmt(std::string(fs), args...)); } - void addTrace(std::shared_ptr<AbstractPos> && e, hintformat hint); + void addTrace(std::shared_ptr<AbstractPos> && e, hintformat hint, bool frame = false); bool hasTrace() const { return !err.traces.empty(); } + + const ErrorInfo & info() { return err; }; }; #define MakeError(newClass, superClass) \ |