diff options
Diffstat (limited to 'src/mongo/shell/assert.js')
-rw-r--r-- | src/mongo/shell/assert.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/mongo/shell/assert.js b/src/mongo/shell/assert.js index 70afc9d41a5..08b095848b2 100644 --- a/src/mongo/shell/assert.js +++ b/src/mongo/shell/assert.js @@ -611,6 +611,28 @@ assert = (function() { return res; }; + assert.dropExceptionsWithCode = function(func, dropCodes, onDrop) { + if (typeof func !== "function") { + doassert('assert.dropExceptionsWithCode 1st argument must be a function'); + } + if (typeof onDrop !== "function") { + doassert('assert.dropExceptionsWithCode 3rd argument must be a function'); + } + if (!Array.isArray(dropCodes)) { + dropCodes = [dropCodes]; + } + + try { + return func(); + } catch (e) { + if (dropCodes.some((ec) => e.code === ec)) { + return onDrop(e); + } else { + throw e; + } + } + }; + assert.throws.automsg = function(func, params) { if (arguments.length === 1) params = []; |