diff options
Diffstat (limited to 'src/libutil/error.hh')
-rw-r--r-- | src/libutil/error.hh | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/libutil/error.hh b/src/libutil/error.hh index c3bb8c0df..0ebeaba61 100644 --- a/src/libutil/error.hh +++ b/src/libutil/error.hh @@ -74,6 +74,8 @@ struct AbstractPos virtual void print(std::ostream & out) const = 0; std::optional<LinesOfCode> getCodeLines() const; + + virtual ~AbstractPos() = default; }; std::ostream & operator << (std::ostream & str, const AbstractPos & pos); @@ -86,6 +88,7 @@ void printCodeLines(std::ostream & out, struct Trace { std::shared_ptr<AbstractPos> pos; hintformat hint; + bool frame; }; struct ErrorInfo { @@ -114,6 +117,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 +157,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) \ |