Skip to content

Commit 2d797b7

Browse files
committed
feat: add Error::Error() constructor
1 parent b06e8c5 commit 2d797b7

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

include/errors/error.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ class Error {
1818
Error(const std::shared_ptr<const std::string>& message_ptr);
1919

2020
public:
21+
22+
/**
23+
* @brief Constructs an empty error object.
24+
*/
25+
Error();
26+
2127
/**
2228
* @brief Returns the error message.
2329
*

src/error.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ namespace errors {
44

55
Error::Error(const std::shared_ptr<const std::string>& message_ptr) : message_ptr(message_ptr) {}
66

7+
Error::Error() {}
8+
79
std::string_view Error::message() const {
810
if (!message_ptr) return "no error";
911
return *message_ptr;

test/error_test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ TEST_CASE("Error Construction") {
88
REQUIRE(err.message() == "unknown error");
99
}
1010

11+
TEST_CASE("Empty Error Construction") {
12+
const errors::Error err;
13+
REQUIRE_FALSE(err);
14+
REQUIRE(err.message() == "no error");
15+
}
16+
1117
TEST_CASE("Error Printing Using OStream") {
1218
const auto err = errors::make("unknown error");
1319
const auto ss = std::stringstream() << err;

0 commit comments

Comments
 (0)