summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2017-10-24 12:27:15 -0400
committerMathias Stearn <mathias@10gen.com>2017-11-02 14:25:21 -0400
commita963b8641cf2ab2cd0ccbbde04993a8224dcf52a (patch)
treef976216a9b16d32f277d598db65b2fcd4ca43e9d /src/mongo
parentd244eadffa8eb5aa714e3e881922c19532e1bd8b (diff)
downloadmongo-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')
-rw-r--r--src/mongo/base/error_codes.tpl.h9
-rw-r--r--src/mongo/base/status_test.cpp8
-rw-r--r--src/mongo/base/system_error.cpp8
-rw-r--r--src/mongo/bson/ugly_bson_integration_test.cpp2
-rw-r--r--src/mongo/client/dbclient_rs.cpp8
-rw-r--r--src/mongo/client/remote_command_retry_scheduler_test.cpp4
-rw-r--r--src/mongo/db/exec/working_set_common.cpp4
-rw-r--r--src/mongo/db/lasterror.cpp4
-rw-r--r--src/mongo/db/pipeline/pipeline_test.cpp4
-rw-r--r--src/mongo/db/repl/storage_interface_impl_test.cpp4
-rw-r--r--src/mongo/db/session.cpp3
-rw-r--r--src/mongo/db/sessions_collection_sharded.cpp4
-rw-r--r--src/mongo/executor/network_interface_asio_command.cpp2
-rw-r--r--src/mongo/executor/network_interface_asio_integration_fixture.cpp2
-rw-r--r--src/mongo/rpc/get_status_from_command_result.cpp2
-rw-r--r--src/mongo/rpc/write_concern_error_detail.cpp4
-rw-r--r--src/mongo/s/catalog_cache.cpp2
-rw-r--r--src/mongo/s/client/parallel.cpp7
-rw-r--r--src/mongo/s/commands/cluster_commands_helpers.cpp2
-rw-r--r--src/mongo/s/commands/cluster_explain.cpp2
-rw-r--r--src/mongo/s/commands/cluster_map_reduce_cmd.cpp2
-rw-r--r--src/mongo/s/commands/commands_public.cpp2
-rw-r--r--src/mongo/s/write_ops/batch_downconvert.cpp4
-rw-r--r--src/mongo/s/write_ops/batched_command_response.cpp6
-rw-r--r--src/mongo/s/write_ops/batched_command_response_test.cpp10
-rw-r--r--src/mongo/scripting/mozjs/exception.cpp2
-rw-r--r--src/mongo/scripting/mozjs/mongo.cpp3
-rw-r--r--src/mongo/transport/asio_utils.h2
-rw-r--r--src/mongo/util/assert_util.h2
29 files changed, 53 insertions, 65 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
diff --git a/src/mongo/bson/ugly_bson_integration_test.cpp b/src/mongo/bson/ugly_bson_integration_test.cpp
index 5cf99f07bda..a3f6bf11fdb 100644
--- a/src/mongo/bson/ugly_bson_integration_test.cpp
+++ b/src/mongo/bson/ugly_bson_integration_test.cpp
@@ -60,7 +60,7 @@ TEST_F(UglyBSONFixture, DuplicateFields) {
<< BSONArray()
<< "documents"
<< BSONArray()),
- ErrorCodes::fromInt(40413));
+ ErrorCodes::Error(40413));
}
} // namespace
diff --git a/src/mongo/client/dbclient_rs.cpp b/src/mongo/client/dbclient_rs.cpp
index a3fc233ab21..3f798f95bda 100644
--- a/src/mongo/client/dbclient_rs.cpp
+++ b/src/mongo/client/dbclient_rs.cpp
@@ -287,8 +287,8 @@ DBClientConnection* DBClientReplicaSet::checkMaster() {
if (!_master->isFailed())
return _master.get();
- monitor->failedHost(
- _masterHost, {ErrorCodes::fromInt(40332), "Last known master host cannot be reached"});
+ monitor->failedHost(_masterHost,
+ {ErrorCodes::Error(40332), "Last known master host cannot be reached"});
h = monitor->getMasterOrUassert(); // old master failed, try again.
}
@@ -320,7 +320,7 @@ DBClientConnection* DBClientReplicaSet::checkMaster() {
const std::string message = str::stream() << "can't connect to new replica set master ["
<< _masterHost.toString() << "]"
<< (errmsg.empty() ? "" : ", err: ") << errmsg;
- monitor->failedHost(_masterHost, {ErrorCodes::fromInt(40333), message});
+ monitor->failedHost(_masterHost, {ErrorCodes::Error(40333), message});
uasserted(ErrorCodes::FailedToSatisfyReadPreference, message);
}
@@ -350,7 +350,7 @@ bool DBClientReplicaSet::checkLastHost(const ReadPreferenceSetting* readPref) {
// Make sure we don't think the host is down.
if (_lastSlaveOkConn->isFailed() || !_getMonitor()->isHostUp(_lastSlaveOkHost)) {
_invalidateLastSlaveOkCache(
- {ErrorCodes::fromInt(40334), "Last slave connection is no longer available"});
+ {ErrorCodes::Error(40334), "Last slave connection is no longer available"});
return false;
}
diff --git a/src/mongo/client/remote_command_retry_scheduler_test.cpp b/src/mongo/client/remote_command_retry_scheduler_test.cpp
index 6b7e844db12..f036b6b3812 100644
--- a/src/mongo/client/remote_command_retry_scheduler_test.cpp
+++ b/src/mongo/client/remote_command_retry_scheduler_test.cpp
@@ -176,7 +176,7 @@ TEST_F(RemoteCommandRetrySchedulerTest, MakeSingleShotRetryPolicy) {
// Doesn't matter what "shouldRetryOnError()" returns since we won't be retrying the remote
// command.
for (int i = 0; i < int(ErrorCodes::MaxError); ++i) {
- auto error = ErrorCodes::fromInt(i);
+ auto error = ErrorCodes::Error(i);
ASSERT_FALSE(policy->shouldRetryOnError(error));
}
}
@@ -189,7 +189,7 @@ TEST_F(RemoteCommandRetrySchedulerTest, MakeRetryPolicy) {
ASSERT_EQUALS(5U, policy->getMaximumAttempts());
ASSERT_EQUALS(Milliseconds(100), policy->getMaximumResponseElapsedTotal());
for (int i = 0; i < int(ErrorCodes::MaxError); ++i) {
- auto error = ErrorCodes::fromInt(i);
+ auto error = ErrorCodes::Error(i);
if (error == ErrorCodes::InternalError || error == ErrorCodes::FailedToParse ||
error == ErrorCodes::InvalidNamespace) {
ASSERT_TRUE(policy->shouldRetryOnError(error));
diff --git a/src/mongo/db/exec/working_set_common.cpp b/src/mongo/db/exec/working_set_common.cpp
index c4fccc9267c..00e41dc2169 100644
--- a/src/mongo/db/exec/working_set_common.cpp
+++ b/src/mongo/db/exec/working_set_common.cpp
@@ -188,7 +188,7 @@ void WorkingSetCommon::getStatusMemberObject(const WorkingSet& ws,
// static
Status WorkingSetCommon::getMemberObjectStatus(const BSONObj& memberObj) {
invariant(WorkingSetCommon::isValidStatusMemberObject(memberObj));
- return Status(ErrorCodes::fromInt(memberObj["code"].numberInt()), memberObj["errmsg"]);
+ return Status(ErrorCodes::Error(memberObj["code"].numberInt()), memberObj["errmsg"]);
}
// static
@@ -203,7 +203,7 @@ std::string WorkingSetCommon::toStatusString(const BSONObj& obj) {
Status unknownStatus(ErrorCodes::UnknownError, "no details available");
return unknownStatus.toString();
}
- Status status(ErrorCodes::fromInt(obj.getIntField("code")), obj.getStringField("errmsg"));
+ Status status(ErrorCodes::Error(obj.getIntField("code")), obj.getStringField("errmsg"));
return status.toString();
}
diff --git a/src/mongo/db/lasterror.cpp b/src/mongo/db/lasterror.cpp
index c9d9aca453e..0595212646e 100644
--- a/src/mongo/db/lasterror.cpp
+++ b/src/mongo/db/lasterror.cpp
@@ -53,7 +53,7 @@ void LastError::setLastError(int code, std::string msg) {
_code = code;
_msg = std::move(msg);
- if (ErrorCodes::isNotMasterError(ErrorCodes::fromInt(_code)))
+ if (ErrorCodes::isNotMasterError(ErrorCodes::Error(_code)))
_hadNotMasterError = true;
}
@@ -91,7 +91,7 @@ bool LastError::appendSelf(BSONObjBuilder& b, bool blankErr) const {
if (_code) {
b.append("code", _code);
- b.append("codeName", ErrorCodes::errorString(ErrorCodes::fromInt(_code)));
+ b.append("codeName", ErrorCodes::errorString(ErrorCodes::Error(_code)));
}
if (_updatedExisting != NotUpdate)
b.appendBool("updatedExisting", _updatedExisting == True);
diff --git a/src/mongo/db/pipeline/pipeline_test.cpp b/src/mongo/db/pipeline/pipeline_test.cpp
index 33bbeddc97f..4cca4bff29d 100644
--- a/src/mongo/db/pipeline/pipeline_test.cpp
+++ b/src/mongo/db/pipeline/pipeline_test.cpp
@@ -2206,7 +2206,7 @@ TEST_F(PipelineInitialSourceNSTest, ChangeStreamIsNotValidIfNotFirstStage) {
setMockReplicationCoordinatorOnOpCtx(ctx->opCtx);
ctx->ns = NamespaceString("a.collection");
auto parseStatus = Pipeline::parse(rawPipeline, ctx).getStatus();
- ASSERT_EQ(parseStatus, ErrorCodes::fromInt(40602));
+ ASSERT_EQ(parseStatus, ErrorCodes::Error(40602));
}
TEST_F(PipelineInitialSourceNSTest, ChangeStreamIsNotValidIfNotFirstStageInFacet) {
@@ -2217,7 +2217,7 @@ TEST_F(PipelineInitialSourceNSTest, ChangeStreamIsNotValidIfNotFirstStageInFacet
setMockReplicationCoordinatorOnOpCtx(ctx->opCtx);
ctx->ns = NamespaceString("a.collection");
auto parseStatus = Pipeline::parseFacetPipeline(rawPipeline, ctx).getStatus();
- ASSERT_EQ(parseStatus, ErrorCodes::fromInt(40600));
+ ASSERT_EQ(parseStatus, ErrorCodes::Error(40600));
ASSERT(std::string::npos != parseStatus.reason().find("$changeStream"));
}
diff --git a/src/mongo/db/repl/storage_interface_impl_test.cpp b/src/mongo/db/repl/storage_interface_impl_test.cpp
index 3f191e6c191..3b2eca9f2f4 100644
--- a/src/mongo/db/repl/storage_interface_impl_test.cpp
+++ b/src/mongo/db/repl/storage_interface_impl_test.cpp
@@ -338,7 +338,7 @@ TEST_F(StorageInterfaceImplTest, GetRollbackIDReturnsBadStatusIfDocumentHasBadFi
{BSON("_id" << StorageInterfaceImpl::kRollbackIdDocumentId << "bad field" << 3),
SnapshotName(0)}};
ASSERT_OK(storage.insertDocuments(opCtx, nss, transformInserts(badDocs)));
- ASSERT_EQUALS(ErrorCodes::fromInt(40415), storage.getRollbackID(opCtx).getStatus());
+ ASSERT_EQUALS(ErrorCodes::Error(40415), storage.getRollbackID(opCtx).getStatus());
}
TEST_F(StorageInterfaceImplTest, GetRollbackIDReturnsBadStatusIfRollbackIDIsNotInt) {
@@ -622,7 +622,7 @@ TEST_F(StorageInterfaceImplTest,
}
auto status = storage.createCollection(opCtx, nss, CollectionOptions());
- ASSERT_EQUALS(ErrorCodes::fromInt(28838), status);
+ ASSERT_EQUALS(ErrorCodes::Error(28838), status);
ASSERT_STRING_CONTAINS(status.reason(), "cannot create a non-capped oplog collection");
}
diff --git a/src/mongo/db/session.cpp b/src/mongo/db/session.cpp
index e5a76b208ec..9db409e8f06 100644
--- a/src/mongo/db/session.cpp
+++ b/src/mongo/db/session.cpp
@@ -507,8 +507,7 @@ void Session::_registerUpdateCacheOnCommit(OperationContext* opCtx,
const auto failBeforeCommitExceptionElem = data["failBeforeCommitExceptionCode"];
if (!failBeforeCommitExceptionElem.eoo()) {
- const auto failureCode =
- ErrorCodes::fromInt(int(failBeforeCommitExceptionElem.Number()));
+ const auto failureCode = ErrorCodes::Error(int(failBeforeCommitExceptionElem.Number()));
uasserted(failureCode,
str::stream() << "Failing write for " << _sessionId << ":" << newTxnNumber
<< " due to failpoint. The write must not be reflected.");
diff --git a/src/mongo/db/sessions_collection_sharded.cpp b/src/mongo/db/sessions_collection_sharded.cpp
index de7699eb962..1d22360e2c4 100644
--- a/src/mongo/db/sessions_collection_sharded.cpp
+++ b/src/mongo/db/sessions_collection_sharded.cpp
@@ -89,7 +89,7 @@ Status SessionsCollectionSharded::refreshSessions(OperationContext* opCtx,
return Status::OK();
}
- auto error = response.isErrCodeSet() ? ErrorCodes::fromInt(response.getErrCode())
+ auto error = response.isErrCodeSet() ? ErrorCodes::Error(response.getErrCode())
: ErrorCodes::UnknownError;
return Status(error, response.getErrMessage());
};
@@ -112,7 +112,7 @@ Status SessionsCollectionSharded::removeRecords(OperationContext* opCtx,
return Status::OK();
}
- auto error = response.isErrCodeSet() ? ErrorCodes::fromInt(response.getErrCode())
+ auto error = response.isErrCodeSet() ? ErrorCodes::Error(response.getErrCode())
: ErrorCodes::UnknownError;
return Status(error, response.getErrMessage());
};
diff --git a/src/mongo/executor/network_interface_asio_command.cpp b/src/mongo/executor/network_interface_asio_command.cpp
index a09b45bc9d1..119115e50e2 100644
--- a/src/mongo/executor/network_interface_asio_command.cpp
+++ b/src/mongo/executor/network_interface_asio_command.cpp
@@ -271,7 +271,7 @@ void NetworkInterfaceASIO::_completedOpCallback(AsyncOp* op) {
void NetworkInterfaceASIO::_networkErrorCallback(AsyncOp* op, const std::error_code& ec) {
ErrorCodes::Error errorCode = (ec.category() == mongoErrorCategory())
- ? ErrorCodes::fromInt(ec.value())
+ ? ErrorCodes::Error(ec.value())
: ErrorCodes::HostUnreachable;
_completeOperation(op, {errorCode, ec.message(), Milliseconds(now() - op->_start)});
}
diff --git a/src/mongo/executor/network_interface_asio_integration_fixture.cpp b/src/mongo/executor/network_interface_asio_integration_fixture.cpp
index 718904b3acb..0a9d8cff01b 100644
--- a/src/mongo/executor/network_interface_asio_integration_fixture.cpp
+++ b/src/mongo/executor/network_interface_asio_integration_fixture.cpp
@@ -154,7 +154,7 @@ void NetworkInterfaceASIOIntegrationFixture::assertWriteError(StringData db,
ASSERT_OK(getStatusFromCommandResult(res.data));
ASSERT(res.data["writeErrors"]);
auto firstWriteError = res.data["writeErrors"].embeddedObject().firstElement().embeddedObject();
- Status writeErrorStatus(ErrorCodes::fromInt(firstWriteError.getIntField("code")),
+ Status writeErrorStatus(ErrorCodes::Error(firstWriteError.getIntField("code")),
firstWriteError.getStringField("errmsg"));
ASSERT_EQ(reason, writeErrorStatus);
}
diff --git a/src/mongo/rpc/get_status_from_command_result.cpp b/src/mongo/rpc/get_status_from_command_result.cpp
index 13c176f44df..3b13923c049 100644
--- a/src/mongo/rpc/get_status_from_command_result.cpp
+++ b/src/mongo/rpc/get_status_from_command_result.cpp
@@ -134,7 +134,7 @@ Status getFirstWriteErrorStatusFromCommandResult(const BSONObj& cmdResponse) {
auto firstWriteErrorObj = firstWriteErrorElem.Obj();
- return Status(ErrorCodes::fromInt(firstWriteErrorObj["code"].Int()),
+ return Status(ErrorCodes::Error(firstWriteErrorObj["code"].Int()),
firstWriteErrorObj["errmsg"].String());
}
diff --git a/src/mongo/rpc/write_concern_error_detail.cpp b/src/mongo/rpc/write_concern_error_detail.cpp
index 1b63898daeb..110131a40ce 100644
--- a/src/mongo/rpc/write_concern_error_detail.cpp
+++ b/src/mongo/rpc/write_concern_error_detail.cpp
@@ -70,7 +70,7 @@ BSONObj WriteConcernErrorDetail::toBSON() const {
if (_isErrCodeSet) {
builder.append(errCode(), _errCode);
- builder.append(errCodeName(), ErrorCodes::errorString(ErrorCodes::fromInt(_errCode)));
+ builder.append(errCodeName(), ErrorCodes::errorString(ErrorCodes::Error(_errCode)));
}
if (_isErrInfoSet)
@@ -96,7 +96,7 @@ bool WriteConcernErrorDetail::parseBSON(const BSONObj& source, string* errMsg) {
return false;
_isErrCodeSet = fieldState == FieldParser::FIELD_SET;
if (_isErrCodeSet) {
- _errCode = ErrorCodes::fromInt(errCodeValue);
+ _errCode = ErrorCodes::Error(errCodeValue);
}
fieldState = FieldParser::extract(source, errInfo, &_errInfo, errMsg);
diff --git a/src/mongo/s/catalog_cache.cpp b/src/mongo/s/catalog_cache.cpp
index 2ca85400c86..0c30441202a 100644
--- a/src/mongo/s/catalog_cache.cpp
+++ b/src/mongo/s/catalog_cache.cpp
@@ -145,7 +145,7 @@ StatusWith<CachedCollectionRoutingInfo> CatalogCache::getCollectionRoutingInfo(
auto shardStatus =
Grid::get(opCtx)->shardRegistry()->getShard(opCtx, dbEntry->primaryShardId);
if (!shardStatus.isOK()) {
- return {ErrorCodes::fromInt(40371),
+ return {ErrorCodes::Error(40371),
str::stream() << "The primary shard for collection " << nss.ns()
<< " could not be loaded due to error "
<< shardStatus.getStatus().toString()};
diff --git a/src/mongo/s/client/parallel.cpp b/src/mongo/s/client/parallel.cpp
index a697d830bf8..fc974828348 100644
--- a/src/mongo/s/client/parallel.cpp
+++ b/src/mongo/s/client/parallel.cpp
@@ -396,10 +396,9 @@ void ParallelSortClusteredCursor::setupVersionAndHandleSlaveOk(
}
} catch (const DBException& dbExcep) {
auto errCode = dbExcep.code();
- if (allowShardVersionFailure &&
- (ErrorCodes::isNotMasterError(ErrorCodes::fromInt(errCode)) ||
- errCode == ErrorCodes::FailedToSatisfyReadPreference ||
- errCode == ErrorCodes::SocketException)) {
+ if (allowShardVersionFailure && (ErrorCodes::isNotMasterError(errCode) ||
+ errCode == ErrorCodes::FailedToSatisfyReadPreference ||
+ errCode == ErrorCodes::SocketException)) {
// It's okay if we don't set the version when talking to a secondary, we can
// be stale in any case.
diff --git a/src/mongo/s/commands/cluster_commands_helpers.cpp b/src/mongo/s/commands/cluster_commands_helpers.cpp
index f5e19270295..c64bab1807d 100644
--- a/src/mongo/s/commands/cluster_commands_helpers.cpp
+++ b/src/mongo/s/commands/cluster_commands_helpers.cpp
@@ -337,7 +337,7 @@ bool appendRawResponses(OperationContext* opCtx,
// a top-level field "code" with this value to the output object.
if (commonErrCode > 0) {
output->append("code", commonErrCode);
- output->append("codeName", ErrorCodes::errorString(ErrorCodes::fromInt(commonErrCode)));
+ output->append("codeName", ErrorCodes::errorString(ErrorCodes::Error(commonErrCode)));
}
return false;
}
diff --git a/src/mongo/s/commands/cluster_explain.cpp b/src/mongo/s/commands/cluster_explain.cpp
index 9970138748e..33dabb52f74 100644
--- a/src/mongo/s/commands/cluster_explain.cpp
+++ b/src/mongo/s/commands/cluster_explain.cpp
@@ -165,7 +165,7 @@ Status ClusterExplain::validateShardResults(const vector<Strategy::CommandResult
// Try to pass up the error code from the shard.
ErrorCodes::Error error = ErrorCodes::OperationFailed;
if (shardResults[i].result["code"].isNumber()) {
- error = ErrorCodes::fromInt(shardResults[i].result["code"].numberInt());
+ error = ErrorCodes::Error(shardResults[i].result["code"].numberInt());
}
return Status(error,
diff --git a/src/mongo/s/commands/cluster_map_reduce_cmd.cpp b/src/mongo/s/commands/cluster_map_reduce_cmd.cpp
index d2385d0caa8..9467232a3cd 100644
--- a/src/mongo/s/commands/cluster_map_reduce_cmd.cpp
+++ b/src/mongo/s/commands/cluster_map_reduce_cmd.cpp
@@ -388,7 +388,7 @@ public:
int code = getUniqueCodeFromCommandResults(mrCommandResults);
if (code != 0) {
result.append("code", code);
- result.append("codeName", ErrorCodes::errorString(ErrorCodes::fromInt(code)));
+ result.append("codeName", ErrorCodes::errorString(ErrorCodes::Error(code)));
}
return false;
diff --git a/src/mongo/s/commands/commands_public.cpp b/src/mongo/s/commands/commands_public.cpp
index 052b62ed215..d1613c8967c 100644
--- a/src/mongo/s/commands/commands_public.cpp
+++ b/src/mongo/s/commands/commands_public.cpp
@@ -487,7 +487,7 @@ public:
int code = getUniqueCodeFromCommandResults(results);
if (code != 0) {
output.append("code", code);
- output.append("codeName", ErrorCodes::errorString(ErrorCodes::fromInt(code)));
+ output.append("codeName", ErrorCodes::errorString(ErrorCodes::Error(code)));
}
if (errored) {
diff --git a/src/mongo/s/write_ops/batch_downconvert.cpp b/src/mongo/s/write_ops/batch_downconvert.cpp
index b117c87671a..e25803dadf3 100644
--- a/src/mongo/s/write_ops/batch_downconvert.cpp
+++ b/src/mongo/s/write_ops/batch_downconvert.cpp
@@ -87,14 +87,14 @@ Status extractGLEErrors(const BSONObj& gleResponse, GLEErrors* errors) {
code == ErrorCodes::WriteConcernFailed || code == ErrorCodes::PrimarySteppedDown) {
// Write concern errors that get returned as regular errors (result may not be ok: 1.0)
errors->wcError.reset(new WriteConcernErrorDetail());
- errors->wcError->setErrCode(ErrorCodes::fromInt(code));
+ errors->wcError->setErrCode(ErrorCodes::Error(code));
errors->wcError->setErrMessage(errMsg);
} else if (!isOK) {
//
// !!! SOME GLE ERROR OCCURRED, UNKNOWN WRITE RESULT !!!
//
- return Status(ErrorCodes::fromInt(code ? code : ErrorCodes::UnknownError), errMsg);
+ return Status(ErrorCodes::Error(code ? code : ErrorCodes::UnknownError), errMsg);
} else if (!err.empty()) {
// Write error
errors->writeError.reset(new WriteErrorDetail);
diff --git a/src/mongo/s/write_ops/batched_command_response.cpp b/src/mongo/s/write_ops/batched_command_response.cpp
index 7e0c592afce..26462777aa9 100644
--- a/src/mongo/s/write_ops/batched_command_response.cpp
+++ b/src/mongo/s/write_ops/batched_command_response.cpp
@@ -601,19 +601,19 @@ const WriteConcernErrorDetail* BatchedCommandResponse::getWriteConcernError() co
Status BatchedCommandResponse::toStatus() const {
if (!getOk()) {
- return Status(ErrorCodes::fromInt(getErrCode()), getErrMessage());
+ return Status(ErrorCodes::Error(getErrCode()), getErrMessage());
}
if (isErrDetailsSet()) {
const WriteErrorDetail* errDetail = getErrDetails().front();
- return Status(ErrorCodes::fromInt(errDetail->getErrCode()), errDetail->getErrMessage());
+ return Status(ErrorCodes::Error(errDetail->getErrCode()), errDetail->getErrMessage());
}
if (isWriteConcernErrorSet()) {
const WriteConcernErrorDetail* errDetail = getWriteConcernError();
- return Status(ErrorCodes::fromInt(errDetail->getErrCode()), errDetail->getErrMessage());
+ return Status(ErrorCodes::Error(errDetail->getErrCode()), errDetail->getErrMessage());
}
return Status::OK();
diff --git a/src/mongo/s/write_ops/batched_command_response_test.cpp b/src/mongo/s/write_ops/batched_command_response_test.cpp
index 3635080a2d5..8ea111425be 100644
--- a/src/mongo/s/write_ops/batched_command_response_test.cpp
+++ b/src/mongo/s/write_ops/batched_command_response_test.cpp
@@ -51,11 +51,11 @@ TEST(BatchedCommandResponse, Basic) {
<< WriteErrorDetail::errInfo(BSON("more info" << 1))
<< WriteErrorDetail::errMessage("index 1 failed too")));
- BSONObj writeConcernError(BSON(
- "code" << 8 << "codeName" << ErrorCodes::errorString(ErrorCodes::fromInt(8)) << "errInfo"
- << BSON("a" << 1)
- << "errmsg"
- << "norepl"));
+ BSONObj writeConcernError(
+ BSON("code" << 8 << "codeName" << ErrorCodes::errorString(ErrorCodes::Error(8)) << "errInfo"
+ << BSON("a" << 1)
+ << "errmsg"
+ << "norepl"));
BSONObj origResponseObj = BSON(BatchedCommandResponse::ok(false)
<< BatchedCommandResponse::errCode(-1)
diff --git a/src/mongo/scripting/mozjs/exception.cpp b/src/mongo/scripting/mozjs/exception.cpp
index 81f84dcb4d5..cc38deadc0f 100644
--- a/src/mongo/scripting/mozjs/exception.cpp
+++ b/src/mongo/scripting/mozjs/exception.cpp
@@ -118,7 +118,7 @@ Status JSErrorReportToStatus(JSContext* cx,
if (report->errorNumber < JSErr_Limit) {
error = ErrorCodes::JSInterpreterFailure;
} else {
- error = ErrorCodes::fromInt(report->errorNumber - JSErr_Limit);
+ error = ErrorCodes::Error(report->errorNumber - JSErr_Limit);
}
}
diff --git a/src/mongo/scripting/mozjs/mongo.cpp b/src/mongo/scripting/mozjs/mongo.cpp
index 922a6931891..debede5bee7 100644
--- a/src/mongo/scripting/mozjs/mongo.cpp
+++ b/src/mongo/scripting/mozjs/mongo.cpp
@@ -623,8 +623,7 @@ void MongoBase::Functions::copyDatabaseWithSCRAM::call(JSContext* cx, JS::CallAr
bool ok = conn->runCommand("admin", command, inputObj);
- ErrorCodes::Error code =
- ErrorCodes::fromInt(inputObj[saslCommandCodeFieldName].numberInt());
+ ErrorCodes::Error code = ErrorCodes::Error(inputObj[saslCommandCodeFieldName].numberInt());
if (!ok || code != ErrorCodes::OK) {
if (code == ErrorCodes::OK)
diff --git a/src/mongo/transport/asio_utils.h b/src/mongo/transport/asio_utils.h
index c06375da31f..e531ed385b6 100644
--- a/src/mongo/transport/asio_utils.h
+++ b/src/mongo/transport/asio_utils.h
@@ -56,7 +56,7 @@ inline Status errorCodeToStatus(const std::error_code& ec) {
// If the ec.category() is a mongoErrorCategory() then this error was propogated from
// mongodb code and we should just pass the error cdoe along as-is.
ErrorCodes::Error errorCode = (ec.category() == mongoErrorCategory())
- ? ErrorCodes::fromInt(ec.value())
+ ? ErrorCodes::Error(ec.value())
// Otherwise it's an error code from the network and we should pass it along as a
// SocketException
: ErrorCodes::SocketException;
diff --git a/src/mongo/util/assert_util.h b/src/mongo/util/assert_util.h
index 1a3852cd328..ba6cfb94d33 100644
--- a/src/mongo/util/assert_util.h
+++ b/src/mongo/util/assert_util.h
@@ -113,7 +113,7 @@ protected:
}
DBException(int code, StringData msg)
- : DBException(Status(code ? ErrorCodes::fromInt(code) : ErrorCodes::UnknownError, msg)) {}
+ : DBException(Status(code ? ErrorCodes::Error(code) : ErrorCodes::UnknownError, msg)) {}
private:
static void traceIfNeeded(const DBException& e);