Skip to content

Commit 96e2a4e

Browse files
throw runtime error instead of dependency error
1 parent 28f0152 commit 96e2a4e

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/cmap/connection.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
import {
2323
MongoCompatibilityError,
2424
MONGODB_ERROR_CODES,
25-
MongoMissingDependencyError,
2625
MongoNetworkError,
2726
MongoNetworkTimeoutError,
2827
MongoOperationTimeoutError,
@@ -868,11 +867,7 @@ export class CryptoConnection extends Connection {
868867
): Promise<Document> {
869868
const { autoEncrypter } = this;
870869
if (!autoEncrypter) {
871-
// TODO(NODE-6065): throw a MongoRuntimeError in Node V7
872-
// @ts-expect-error No cause provided because there is no underlying error.
873-
throw new MongoMissingDependencyError('No AutoEncrypter available for encryption', {
874-
dependencyName: 'n/a'
875-
});
870+
throw new MongoRuntimeError('No AutoEncrypter available for encryption');
876871
}
877872

878873
const serverWireVersion = maxWireVersion(this);

test/unit/cmap/connection.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as sinon from 'sinon';
66
import { setTimeout } from 'timers/promises';
77

88
import { connect } from '../../../src/cmap/connect';
9-
import { Connection, SizedMessageTransform } from '../../../src/cmap/connection';
9+
import { Connection, CryptoConnection, SizedMessageTransform } from '../../../src/cmap/connection';
1010
import { MongoNetworkTimeoutError, MongoRuntimeError } from '../../../src/error';
1111
import { MongoClientAuthProviders } from '../../../src/mongo_client_auth_providers';
1212
import { isHello, MongoDBCollectionNamespace, ns, promiseWithResolvers } from '../../../src/utils';
@@ -401,4 +401,18 @@ describe('new Connection()', function () {
401401
expect(error).to.be.instanceOf(MongoRuntimeError);
402402
});
403403
});
404+
405+
it('CryptoConnection.command() throws if no autoEncrypter is configured', async function () {
406+
const error = await connect({
407+
...connectionOptionsDefaults,
408+
hostAddress: server.hostAddress(),
409+
authProviders: new MongoClientAuthProviders(),
410+
connectionType: CryptoConnection,
411+
extendedMetadata: Promise.resolve({})
412+
}).catch(e => e);
413+
414+
expect(error)
415+
.to.be.instanceOf(MongoRuntimeError)
416+
.to.match(/No AutoEncrypter available for encryption/);
417+
});
404418
});

0 commit comments

Comments
 (0)