diff options
author | Yu Jin Kang Park <yujin.kang@mongodb.com> | 2022-12-19 14:33:06 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-12-19 15:32:32 +0000 |
commit | 72b203af76e771c0705bfa657c9df76fa48c4cd5 (patch) | |
tree | 32029b2d732cf626d705e1cd90d24b6ed9d5b443 | |
parent | 3aac7ce4d77075f6f06f73aea29c16e676f3f038 (diff) | |
download | mongo-72b203af76e771c0705bfa657c9df76fa48c4cd5.tar.gz |
SERVER-71512 Fix assert.commandWorkedOrFailedWithCode
-rw-r--r-- | src/mongo/shell/assert.js | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/mongo/shell/assert.js b/src/mongo/shell/assert.js index c42476a39f4..2e153854353 100644 --- a/src/mongo/shell/assert.js +++ b/src/mongo/shell/assert.js @@ -845,10 +845,12 @@ assert = (function() { assert.commandWorkedOrFailedWithCode = function commandWorkedOrFailedWithCode( res, errorCodeSet, msg) { - if (!res.ok) { - return assert.commandFailedWithCode(res, errorCodeSet, msg); - } else { + try { + // First check if the command worked. return assert.commandWorked(res, msg); + } catch (e) { + // If the command did not work, assert it failed with one of the specified codes. + return assert.commandFailedWithCode(res, errorCodeSet, msg); } }; |