diff --git a/error/include/error/error.hpp b/error/include/error/error.hpp index 2be232b..5d4dc2b 100644 --- a/error/include/error/error.hpp +++ b/error/include/error/error.hpp @@ -48,6 +48,13 @@ struct Error : public std::exception { const char* what() const noexcept override; }; +/** + * @brief Creates a new error object with the given message. + * @param msg The error message. + * @return A new error object. + */ +Error make(const std::string& msg); + /** * @brief Creates a new error object with a formatted message. * @tparam T Variadic template parameter pack for format arguments. diff --git a/error/src/error.cpp b/error/src/error.cpp index c3b119b..eb41c2a 100644 --- a/error/src/error.cpp +++ b/error/src/error.cpp @@ -10,6 +10,8 @@ std::ostream& operator<<(std::ostream& os, const error::Error& err) { const char* Error::what() const noexcept { return message.c_str(); } +Error make(const std::string& msg) { return Error(msg); } + bool operator==(const Error& lhs, const Error& rhs) { return lhs.message == rhs.message; } diff --git a/error/test/error_test.cpp b/error/test/error_test.cpp index c4fc7a0..3e9ed3e 100644 --- a/error/test/error_test.cpp +++ b/error/test/error_test.cpp @@ -6,7 +6,7 @@ #include TEST_CASE("Error Construction") { - const error::Error err("unknown error"); + const error::Error err = error::make("unknown error"); REQUIRE(err.message == "unknown error"); }