Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Error: Add make Function #32

Merged
merged 1 commit into from
Jul 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions error/include/error/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions error/src/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion error/test/error_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <string>

TEST_CASE("Error Construction") {
const error::Error err("unknown error");
const error::Error err = error::make("unknown error");
REQUIRE(err.message == "unknown error");
}

Expand Down