From 0795f0f0f9f8bcd0695397c3e9338c4cb3f0d280 Mon Sep 17 00:00:00 2001 From: gagik Date: Thu, 10 Oct 2024 15:56:45 +0200 Subject: [PATCH 1/3] Remove custom handling of this? --- packages/shell-api/src/collection.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/packages/shell-api/src/collection.ts b/packages/shell-api/src/collection.ts index 1723425bb1..a8c699ff5c 100644 --- a/packages/shell-api/src/collection.ts +++ b/packages/shell-api/src/collection.ts @@ -1335,15 +1335,6 @@ export default class Collection extends ShellApiWithMongoClass { return all.sort((a, b) => b.nIndexesWas - a.nIndexesWas)[0]; } - if (error?.codeName === 'IndexNotFound') { - return { - ok: error.ok, - errmsg: error.errmsg, - code: error.code, - codeName: error.codeName, - }; - } - throw error; } } From 3f6c223b4f2be8698eb99b0d199e0b6f3b097ac3 Mon Sep 17 00:00:00 2001 From: gagik Date: Thu, 17 Oct 2024 16:17:43 +0200 Subject: [PATCH 2/3] update expected error test to be a catch --- packages/shell-api/src/collection.spec.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/shell-api/src/collection.spec.ts b/packages/shell-api/src/collection.spec.ts index 3f218d662c..91776ec32a 100644 --- a/packages/shell-api/src/collection.spec.ts +++ b/packages/shell-api/src/collection.spec.ts @@ -1165,26 +1165,29 @@ describe('Collection', function () { context( 'when serviceProvider.dropIndexes rejects IndexNotFound', function () { + let expectedError: Error; beforeEach(function () { - const error = new Error('index not found with name [index_1]'); - Object.assign(error, { + expectedError = new Error('index not found with name [index_1]'); + Object.assign(expectedError, { ok: 0, errmsg: 'index not found with name [index_1]', code: 27, codeName: 'IndexNotFound', - name: 'MongoError', + name: 'MongoServerError', }); - serviceProvider.runCommandWithCheck.rejects(error); + serviceProvider.runCommandWithCheck.rejects(expectedError); }); it('returns the error as object', async function () { - expect(await collection.dropIndexes('index_1')).to.deep.equal({ - ok: 0, - errmsg: 'index not found with name [index_1]', - code: 27, - codeName: 'IndexNotFound', - }); + let caughtError: Error | undefined; + expect( + await collection + .dropIndexes('index_1') + .catch((err) => (caughtError = err)) + ); + + expect(caughtError).to.deep.equal(expectedError); }); } ); From e1b4e279a8dce46286b6f322caddc9f257f135c0 Mon Sep 17 00:00:00 2001 From: gagik Date: Thu, 17 Oct 2024 16:19:35 +0200 Subject: [PATCH 3/3] remove expect wrap --- packages/shell-api/src/collection.spec.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/shell-api/src/collection.spec.ts b/packages/shell-api/src/collection.spec.ts index 91776ec32a..95d16c2fae 100644 --- a/packages/shell-api/src/collection.spec.ts +++ b/packages/shell-api/src/collection.spec.ts @@ -1181,11 +1181,9 @@ describe('Collection', function () { it('returns the error as object', async function () { let caughtError: Error | undefined; - expect( - await collection - .dropIndexes('index_1') - .catch((err) => (caughtError = err)) - ); + await collection + .dropIndexes('index_1') + .catch((err) => (caughtError = err)); expect(caughtError).to.deep.equal(expectedError); });