diff options
author | Mathias Stearn <mathias@10gen.com> | 2017-10-24 12:27:15 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2017-11-02 14:25:21 -0400 |
commit | a963b8641cf2ab2cd0ccbbde04993a8224dcf52a (patch) | |
tree | f976216a9b16d32f277d598db65b2fcd4ca43e9d /src/mongo/base | |
parent | d244eadffa8eb5aa714e3e881922c19532e1bd8b (diff) | |
download | mongo-a963b8641cf2ab2cd0ccbbde04993a8224dcf52a.tar.gz |
SERVER-31629 Replace ErrorCodes::fromInt() with ErrorCodes::Error()
No reason to have two ways to express the same thing, and we can't get rid of
ErrorCodes::Error().
Diffstat (limited to 'src/mongo/base')
-rw-r--r-- | src/mongo/base/error_codes.tpl.h | 9 | ||||
-rw-r--r-- | src/mongo/base/status_test.cpp | 8 | ||||
-rw-r--r-- | src/mongo/base/system_error.cpp | 8 |
3 files changed, 8 insertions, 17 deletions
diff --git a/src/mongo/base/error_codes.tpl.h b/src/mongo/base/error_codes.tpl.h index a2b2cbb7f06..ff4d3b0822d 100644 --- a/src/mongo/base/error_codes.tpl.h +++ b/src/mongo/base/error_codes.tpl.h @@ -73,15 +73,6 @@ public: static Error fromString(StringData name); /** - * Casts an integer "code" to an Error. Unrecognized codes are preserved, meaning - * that the result of a call to fromInt() may not be one of the values in the - * Error enumeration. - */ - static Error fromInt(int code) { - return static_cast<Error>(code); - } - - /** * Generic predicate to test if a given error code is in a category. * * This version is intended to simplify forwarding by Status and DBException. Non-generic diff --git a/src/mongo/base/status_test.cpp b/src/mongo/base/status_test.cpp index 57b2ac8a2d1..ba57448939f 100644 --- a/src/mongo/base/status_test.cpp +++ b/src/mongo/base/status_test.cpp @@ -199,10 +199,10 @@ TEST(Cloning, OKIsNotRefCounted) { } TEST(Parsing, CodeToEnum) { - ASSERT_EQUALS(ErrorCodes::TypeMismatch, ErrorCodes::fromInt(ErrorCodes::TypeMismatch)); - ASSERT_EQUALS(ErrorCodes::UnknownError, ErrorCodes::fromInt(ErrorCodes::UnknownError)); - ASSERT_EQUALS(ErrorCodes::MaxError, ErrorCodes::fromInt(ErrorCodes::MaxError)); - ASSERT_EQUALS(ErrorCodes::OK, ErrorCodes::fromInt(0)); + ASSERT_EQUALS(ErrorCodes::TypeMismatch, ErrorCodes::Error(int(ErrorCodes::TypeMismatch))); + ASSERT_EQUALS(ErrorCodes::UnknownError, ErrorCodes::Error(int(ErrorCodes::UnknownError))); + ASSERT_EQUALS(ErrorCodes::MaxError, ErrorCodes::Error(int(ErrorCodes::MaxError))); + ASSERT_EQUALS(ErrorCodes::OK, ErrorCodes::Error(0)); } TEST(Transformers, ExceptionToStatus) { diff --git a/src/mongo/base/system_error.cpp b/src/mongo/base/system_error.cpp index 8af0d86384d..d62237a7fb2 100644 --- a/src/mongo/base/system_error.cpp +++ b/src/mongo/base/system_error.cpp @@ -48,7 +48,7 @@ public: } std::string message(int ev) const override { - return ErrorCodes::errorString(ErrorCodes::fromInt(ev)); + return ErrorCodes::errorString(ErrorCodes::Error(ev)); } // We don't really want to override this function, but to override the second we need to, @@ -58,7 +58,7 @@ public: } bool equivalent(const std::error_code& code, int condition) const noexcept override { - switch (ErrorCodes::fromInt(condition)) { + switch (ErrorCodes::Error(condition)) { case ErrorCodes::OK: // Make ErrorCodes::OK to be equivalent to the default constructed error code. return code == std::error_code(); @@ -77,11 +77,11 @@ const std::error_category& mongoErrorCategory() { } std::error_code make_error_code(ErrorCodes::Error code) { - return std::error_code(ErrorCodes::fromInt(code), mongoErrorCategory()); + return std::error_code(ErrorCodes::Error(code), mongoErrorCategory()); } std::error_condition make_error_condition(ErrorCodes::Error code) { - return std::error_condition(ErrorCodes::fromInt(code), mongoErrorCategory()); + return std::error_condition(ErrorCodes::Error(code), mongoErrorCategory()); } } // namespace mongo |