diff options
author | Mathias Stearn <mathias@10gen.com> | 2017-08-14 16:16:07 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2017-08-16 16:28:02 -0400 |
commit | fe72cc35ff8af7bf421d29c668e4d50c048d141b (patch) | |
tree | d7e238caf2f7a4b18b3036ea33b5a0b95d9b2e10 /src | |
parent | dee1c5c4bf9d15d8ee7138130ad097a4ee7e523b (diff) | |
download | mongo-fe72cc35ff8af7bf421d29c668e4d50c048d141b.tar.gz |
SERVER-30580 Always use errorString() when streaming an ErrorCode::Error
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/base/generate_error_codes.py | 13 | ||||
-rw-r--r-- | src/mongo/base/status.cpp | 4 | ||||
-rw-r--r-- | src/mongo/base/status.h | 5 | ||||
-rw-r--r-- | src/mongo/bson/util/builder.h | 4 |
4 files changed, 13 insertions, 13 deletions
diff --git a/src/mongo/base/generate_error_codes.py b/src/mongo/base/generate_error_codes.py index 9c66fb6b9fc..b431cff415c 100644 --- a/src/mongo/base/generate_error_codes.py +++ b/src/mongo/base/generate_error_codes.py @@ -301,6 +301,7 @@ class cpp_generator(base_generator): #pragma once #include <string> #include <cstdint> +#include <iosfwd> #include "mongo/base/string_data.h" namespace mongo { /** @@ -329,9 +330,13 @@ namespace mongo { * that the result of a call to fromInt() may not be one of the values in the * Error enumeration. */ - static Error fromInt(int code); + static Error fromInt(int code) { + return static_cast<Error>(code); + } %(error_code_class_predicate_declarations)s; }; + + std::ostream& operator<<(std::ostream& stream, ErrorCodes::Error code); } // namespace mongo ''' @@ -369,15 +374,15 @@ namespace mongo { std::string ErrorCodes::errorString(Error err) { switch (err) { %(symbol_to_string_cases)s; - default: return mongoutils::str::stream() << "Location" << err; + default: return mongoutils::str::stream() << "Location" << int(err); } } ErrorCodes::Error ErrorCodes::fromString(StringData name) { %(string_to_symbol_cases)s; return UnknownError; } - ErrorCodes::Error ErrorCodes::fromInt(int code) { - return static_cast<Error>(code); + std::ostream& operator<<(std::ostream& stream, ErrorCodes::Error code) { + return stream << ErrorCodes::errorString(code); } %(error_code_class_predicate_definitions)s namespace { diff --git a/src/mongo/base/status.cpp b/src/mongo/base/status.cpp index 90bdec72457..a5bd0a59066 100644 --- a/src/mongo/base/status.cpp +++ b/src/mongo/base/status.cpp @@ -57,10 +57,6 @@ std::ostream& operator<<(std::ostream& os, const Status& status) { return os << status.codeString() << " " << status.reason(); } -std::ostream& operator<<(std::ostream& os, ErrorCodes::Error code) { - return os << ErrorCodes::errorString(code); -} - std::string Status::toString() const { std::ostringstream ss; ss << codeString(); diff --git a/src/mongo/base/status.h b/src/mongo/base/status.h index da98ad72c58..3a4462d057d 100644 --- a/src/mongo/base/status.h +++ b/src/mongo/base/status.h @@ -185,12 +185,7 @@ inline bool operator==(const ErrorCodes::Error lhs, const Status& rhs); inline bool operator!=(const ErrorCodes::Error lhs, const Status& rhs); -// -// Convenience method for unittest code. Please use accessors otherwise. -// - std::ostream& operator<<(std::ostream& os, const Status& status); -std::ostream& operator<<(std::ostream& os, ErrorCodes::Error); } // namespace mongo diff --git a/src/mongo/bson/util/builder.h b/src/mongo/bson/util/builder.h index abd4dd95f90..9d4ad89d1a0 100644 --- a/src/mongo/bson/util/builder.h +++ b/src/mongo/bson/util/builder.h @@ -443,6 +443,10 @@ public: append(typeName(type)); return *this; } + StringBuilderImpl& operator<<(ErrorCodes::Error code) { + append(ErrorCodes::errorString(code)); + return *this; + } void appendDoubleNice(double x) { const int prev = _buf.l; |