Skip to content

Rename Namespace to errors #78

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 22, 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
6 changes: 3 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ A `C++`_ package that provides utilities for error handling.
API Docs
--------

.. doxygenfunction:: error::make
.. doxygenfunction:: errors::make

.. doxygenfunction:: error::format
.. doxygenfunction:: errors::format

.. doxygenstruct:: error::Error
.. doxygenstruct:: errors::Error
:members:

License
Expand Down
18 changes: 9 additions & 9 deletions include/errors/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <string>
#include <utility>

namespace error {
namespace errors {

/**
* @brief Represents error information.
Expand All @@ -26,13 +26,13 @@ struct Error {
* stream.
*
* @code{.cpp}
* const auto err = error::make("unknown error");
* const auto err = errors::make("unknown error");
*
* // Print "error: unknown error"
* std::cout << err << std::endl;
* @endcode
*/
friend std::ostream& operator<<(std::ostream& os, const error::Error& err);
friend std::ostream& operator<<(std::ostream& os, const errors::Error& err);

/**
* @brief Checks if two error objects are equal.
Expand All @@ -43,7 +43,7 @@ struct Error {
* This operator allows the comparison of two error objects using the == operator.
*
* @code{.cpp}
* const auto err = error::make("unknown error");
* const auto err = errors::make("unknown error");
* const auto other_err = err;
*
* assert(err == other_err);
Expand All @@ -60,8 +60,8 @@ struct Error {
* This operator allows the comparison of two error objects using the != operator.
*
* @code{.cpp}
* const auto err = error::make("unknown error");
* const auto other_err = error::make("other error");
* const auto err = errors::make("unknown error");
* const auto other_err = errors::make("other error");
*
* assert(err != other_err);
* @endcode
Expand All @@ -85,14 +85,14 @@ Error make(const std::string& msg);
*/
template <typename... T>
Error format(fmt::format_string<T...> fmt, T&&... args) {
return error::make(fmt::format(fmt, std::forward<T>(args)...));
return errors::make(fmt::format(fmt, std::forward<T>(args)...));
}

} // namespace error

template <>
struct fmt::formatter<error::Error> {
struct fmt::formatter<errors::Error> {
format_parse_context::iterator parse(format_parse_context& ctx) const;
format_context::iterator format(const error::Error& err,
format_context::iterator format(const errors::Error& err,
format_context& ctx) const;
};
10 changes: 5 additions & 5 deletions src/error.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <errors/error.hpp>

namespace error {
namespace errors {

std::ostream& operator<<(std::ostream& os, const error::Error& err) {
std::ostream& operator<<(std::ostream& os, const errors::Error& err) {
return os << "error: " << err.message;
}

Expand All @@ -20,13 +20,13 @@ Error make(const std::string& msg) { return Error{.message = msg}; }

namespace fmt {

format_parse_context::iterator formatter<error::Error>::parse(
format_parse_context::iterator formatter<errors::Error>::parse(
format_parse_context& ctx) const {
return ctx.begin();
}

format_context::iterator formatter<error::Error>::format(
const error::Error& err, format_context& ctx) const {
format_context::iterator formatter<errors::Error>::format(
const errors::Error& err, format_context& ctx) const {
return format_to(ctx.out(), "error: {}", err.message);
}

Expand Down
10 changes: 5 additions & 5 deletions test/error_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@
#include <string>

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

TEST_CASE("Error Construction With Formatting") {
const error::Error err = error::format("HTTP error {}", 404);
const errors::Error err = errors::format("HTTP error {}", 404);
REQUIRE(err.message == "HTTP error 404");
}

TEST_CASE("Error Comparison") {
const auto err = error::make("unknown error");
const auto err = errors::make("unknown error");
const auto err_copy = err;
CHECK(err == err_copy);
CHECK_FALSE(err != err_copy);
const auto other_err = error::make("other error");
const auto other_err = errors::make("other error");
CHECK_FALSE(err == other_err);
CHECK(err != other_err);
}

TEST_CASE("Error Printing") {
const auto err = error::make("unknown error");
const auto err = errors::make("unknown error");

SECTION("Using ostream") {
const auto ss = std::stringstream() << err;
Expand Down