diff --git a/src/common/error.h b/src/common/error.h index f9e20058..29a695e2 100644 --- a/src/common/error.h +++ b/src/common/error.h @@ -39,15 +39,32 @@ class SourceError { String mMessage{}; Kind mKind{Error}; }; - /// @brief Construct a new source error. /// @param data The source error data. explicit SourceError(const Vector& data) : mData(data) {} /// @brief Get the source error data. /// @return The source error data. - auto GetData() const -> const Vector& { return mData; } + auto GetData() const -> const Vector&; + + /// @brief Append a new Info source error. + auto WithInfo(const String& message, const std::optional& + location = std::nullopt) -> SourceError&; + /// @brief Append a new Note source error. + auto WithNote(const String& message, const std::optional& + location = std::nullopt) -> SourceError&; + /// @brief Append a new Warning source error. + auto WithWarning(const String& message, const std::optional& + location = std::nullopt) -> SourceError&; private: Vector mData; }; +/// @brief It displays an error message and immediately exits the program. +/// @param error The error to display. +[[noreturn]] auto FatalError(const Error& error) -> void; + +// Group: fmt utils +auto format_as(const Error& error) -> String; +auto format_as(const SourceError& error) -> String; + } // namespace snowball