Skip to content

Commit ae6bc90

Browse files
committed
feat(error): add a make function to create a new error
1 parent 227f7c8 commit ae6bc90

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

error/include/error/error.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ struct Error : public std::exception {
4848
const char* what() const noexcept override;
4949
};
5050

51+
/**
52+
* @brief Creates a new error object with the given message.
53+
* @param msg The error message.
54+
* @return A new error object.
55+
*/
56+
Error make(const std::string& msg);
57+
5158
/**
5259
* @brief Creates a new error object with a formatted message.
5360
* @tparam T Variadic template parameter pack for format arguments.

error/src/error.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ std::ostream& operator<<(std::ostream& os, const error::Error& err) {
1010

1111
const char* Error::what() const noexcept { return message.c_str(); }
1212

13+
Error make(const std::string& msg) { return Error(msg); }
14+
1315
bool operator==(const Error& lhs, const Error& rhs) {
1416
return lhs.message == rhs.message;
1517
}

error/test/error_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <string>
77

88
TEST_CASE("Error Construction") {
9-
const error::Error err("unknown error");
9+
const error::Error err = error::make("unknown error");
1010
REQUIRE(err.message == "unknown error");
1111
}
1212

0 commit comments

Comments
 (0)