Skip to content

Commit 9f7a7ba

Browse files
authored
refactor: rename namespace to errors (#78)
1 parent bd0a07d commit 9f7a7ba

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

docs/index.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ A `C++`_ package that provides utilities for error handling.
88
API Docs
99
--------
1010

11-
.. doxygenfunction:: error::make
11+
.. doxygenfunction:: errors::make
1212

13-
.. doxygenfunction:: error::format
13+
.. doxygenfunction:: errors::format
1414

15-
.. doxygenstruct:: error::Error
15+
.. doxygenstruct:: errors::Error
1616
:members:
1717

1818
License

include/errors/error.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <string>
77
#include <utility>
88

9-
namespace error {
9+
namespace errors {
1010

1111
/**
1212
* @brief Represents error information.
@@ -26,13 +26,13 @@ struct Error {
2626
* stream.
2727
*
2828
* @code{.cpp}
29-
* const auto err = error::make("unknown error");
29+
* const auto err = errors::make("unknown error");
3030
*
3131
* // Print "error: unknown error"
3232
* std::cout << err << std::endl;
3333
* @endcode
3434
*/
35-
friend std::ostream& operator<<(std::ostream& os, const error::Error& err);
35+
friend std::ostream& operator<<(std::ostream& os, const errors::Error& err);
3636

3737
/**
3838
* @brief Checks if two error objects are equal.
@@ -43,7 +43,7 @@ struct Error {
4343
* This operator allows the comparison of two error objects using the == operator.
4444
*
4545
* @code{.cpp}
46-
* const auto err = error::make("unknown error");
46+
* const auto err = errors::make("unknown error");
4747
* const auto other_err = err;
4848
*
4949
* assert(err == other_err);
@@ -60,8 +60,8 @@ struct Error {
6060
* This operator allows the comparison of two error objects using the != operator.
6161
*
6262
* @code{.cpp}
63-
* const auto err = error::make("unknown error");
64-
* const auto other_err = error::make("other error");
63+
* const auto err = errors::make("unknown error");
64+
* const auto other_err = errors::make("other error");
6565
*
6666
* assert(err != other_err);
6767
* @endcode
@@ -85,14 +85,14 @@ Error make(const std::string& msg);
8585
*/
8686
template <typename... T>
8787
Error format(fmt::format_string<T...> fmt, T&&... args) {
88-
return error::make(fmt::format(fmt, std::forward<T>(args)...));
88+
return errors::make(fmt::format(fmt, std::forward<T>(args)...));
8989
}
9090

9191
} // namespace error
9292

9393
template <>
94-
struct fmt::formatter<error::Error> {
94+
struct fmt::formatter<errors::Error> {
9595
format_parse_context::iterator parse(format_parse_context& ctx) const;
96-
format_context::iterator format(const error::Error& err,
96+
format_context::iterator format(const errors::Error& err,
9797
format_context& ctx) const;
9898
};

src/error.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include <errors/error.hpp>
22

3-
namespace error {
3+
namespace errors {
44

5-
std::ostream& operator<<(std::ostream& os, const error::Error& err) {
5+
std::ostream& operator<<(std::ostream& os, const errors::Error& err) {
66
return os << "error: " << err.message;
77
}
88

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

2121
namespace fmt {
2222

23-
format_parse_context::iterator formatter<error::Error>::parse(
23+
format_parse_context::iterator formatter<errors::Error>::parse(
2424
format_parse_context& ctx) const {
2525
return ctx.begin();
2626
}
2727

28-
format_context::iterator formatter<error::Error>::format(
29-
const error::Error& err, format_context& ctx) const {
28+
format_context::iterator formatter<errors::Error>::format(
29+
const errors::Error& err, format_context& ctx) const {
3030
return format_to(ctx.out(), "error: {}", err.message);
3131
}
3232

test/error_test.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,27 @@
66
#include <string>
77

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

1313
TEST_CASE("Error Construction With Formatting") {
14-
const error::Error err = error::format("HTTP error {}", 404);
14+
const errors::Error err = errors::format("HTTP error {}", 404);
1515
REQUIRE(err.message == "HTTP error 404");
1616
}
1717

1818
TEST_CASE("Error Comparison") {
19-
const auto err = error::make("unknown error");
19+
const auto err = errors::make("unknown error");
2020
const auto err_copy = err;
2121
CHECK(err == err_copy);
2222
CHECK_FALSE(err != err_copy);
23-
const auto other_err = error::make("other error");
23+
const auto other_err = errors::make("other error");
2424
CHECK_FALSE(err == other_err);
2525
CHECK(err != other_err);
2626
}
2727

2828
TEST_CASE("Error Printing") {
29-
const auto err = error::make("unknown error");
29+
const auto err = errors::make("unknown error");
3030

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

0 commit comments

Comments
 (0)