diff options
author | Moustafa Maher <m.maher@10gen.com> | 2021-03-25 19:22:59 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-04-01 23:30:27 +0000 |
commit | d4840264c7df06f969267806fdf2623d1bb6f6d6 (patch) | |
tree | d1d9dfe838ba61d3c65d3e61458bb22504994c39 /src/mongo/s/commands/cluster_collection_mod_cmd.cpp | |
parent | a1cb32b607ffff4014a203419cc60598f206b7e0 (diff) | |
download | mongo-d4840264c7df06f969267806fdf2623d1bb6f6d6.tar.gz |
SERVER-54436 Refactor validateResult method from cluster_create_indexes to use checkIsErrorStatus
Diffstat (limited to 'src/mongo/s/commands/cluster_collection_mod_cmd.cpp')
-rw-r--r-- | src/mongo/s/commands/cluster_collection_mod_cmd.cpp | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/src/mongo/s/commands/cluster_collection_mod_cmd.cpp b/src/mongo/s/commands/cluster_collection_mod_cmd.cpp index c8ee99af54d..0d895756b91 100644 --- a/src/mongo/s/commands/cluster_collection_mod_cmd.cpp +++ b/src/mongo/s/commands/cluster_collection_mod_cmd.cpp @@ -117,26 +117,36 @@ public: void validateResult(const BSONObj& resultObj) final { auto ctx = IDLParserErrorContext("CollModReply"); + if (checkIsErrorStatus(resultObj, ctx)) { + return; + } + StringDataSet ignorableFields({kWriteConcernErrorFieldName, ErrorReply::kOkFieldName, kTopologyVersionFieldName, kRawFieldName}); - if (!checkIsErrorStatus(resultObj, ctx)) { - auto reply = Reply::parse(ctx, resultObj.removeFields(ignorableFields)); - coll_mod_reply_validation::validateReply(reply); - - if (resultObj.hasField(kRawFieldName)) { - const auto& rawData = resultObj[kRawFieldName]; - if (ctx.checkAndAssertType(rawData, Object)) { - for (const auto& element : rawData.Obj()) { - const auto& shardReply = element.Obj(); - if (!checkIsErrorStatus(shardReply, ctx)) { - auto reply = - Reply::parse(ctx, shardReply.removeFields(ignorableFields)); - coll_mod_reply_validation::validateReply(reply); - } - } - } + auto reply = Reply::parse(ctx, resultObj.removeFields(ignorableFields)); + coll_mod_reply_validation::validateReply(reply); + + if (!resultObj.hasField(kRawFieldName)) { + return; + } + + const auto& rawData = resultObj[kRawFieldName]; + if (!ctx.checkAndAssertType(rawData, Object)) { + return; + } + + auto rawCtx = IDLParserErrorContext(kRawFieldName, &ctx); + for (const auto& element : rawData.Obj()) { + if (!rawCtx.checkAndAssertType(element, Object)) { + return; + } + + const auto& shardReply = element.Obj(); + if (!checkIsErrorStatus(shardReply, ctx)) { + auto reply = Reply::parse(ctx, shardReply.removeFields(ignorableFields)); + coll_mod_reply_validation::validateReply(reply); } } } |