From efe368fa7a6b4c1ca6077fdb2560a33dfdc82337 Mon Sep 17 00:00:00 2001 From: Jason Rassi Date: Tue, 9 Dec 2014 16:13:17 -0500 Subject: SERVER-16469 findAndModify runImpl(): improve error reporting Previously, findAndModify ignored errors encountered in calls to PlanExecutor::getNext() when searching for the document to modify. Now, errors are bubbled up to the user. --- src/mongo/db/commands/find_and_modify.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/mongo/db/commands/find_and_modify.cpp b/src/mongo/db/commands/find_and_modify.cpp index 66250c8af81..56410a59916 100644 --- a/src/mongo/db/commands/find_and_modify.cpp +++ b/src/mongo/db/commands/find_and_modify.cpp @@ -35,6 +35,7 @@ #include "mongo/db/commands.h" #include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/dbhelpers.h" +#include "mongo/db/exec/working_set_common.h" #include "mongo/db/projection.h" #include "mongo/db/ops/delete.h" #include "mongo/db/ops/update.h" @@ -239,9 +240,24 @@ namespace mongo { scoped_ptr exec(rawExec); - if (PlanExecutor::ADVANCED == exec->getNext(&doc, NULL)) { + PlanExecutor::ExecState state = exec->getNext(&doc, NULL); + if (PlanExecutor::ADVANCED == state) { found = true; } + else if (PlanExecutor::FAILURE == state || PlanExecutor::DEAD == state) { + if (PlanExecutor::FAILURE == state && + WorkingSetCommon::isValidStatusMemberObject(doc)) { + const Status errorStatus = WorkingSetCommon::getMemberObjectStatus(doc); + invariant(!errorStatus.isOK()); + uasserted(errorStatus.code(), errorStatus.reason()); + } + uasserted(ErrorCodes::OperationFailed, + str::stream() << "executor returned " << PlanExecutor::statestr(state) + << " while finding document to update"); + } + else { + invariant(PlanExecutor::IS_EOF == state); + } } BSONObj queryModified = query; -- cgit v1.2.1