From a8653babe719c1af7b7c39b7a51297cf68f183d8 Mon Sep 17 00:00:00 2001 From: Warren James Date: Mon, 7 Aug 2023 14:19:15 -0400 Subject: [PATCH 01/37] feat(NODE-5484)!: make MongoError constructors internal and remove Node14 cause assignment logic --- src/client-side-encryption/errors.ts | 3 +- src/error.ts | 165 ++++++++++++++++----------- 2 files changed, 102 insertions(+), 66 deletions(-) diff --git a/src/client-side-encryption/errors.ts b/src/client-side-encryption/errors.ts index d187bac0d97..aaa0687e50f 100644 --- a/src/client-side-encryption/errors.ts +++ b/src/client-side-encryption/errors.ts @@ -1,10 +1,11 @@ import { type Document } from '../bson'; +import { MongoError } from '../error'; /** * @public * An error indicating that something went wrong specifically with MongoDB Client Encryption */ -export class MongoCryptError extends Error { +export class MongoCryptError extends MongoError { /** @internal */ constructor(message: string, options: { cause?: Error } = {}) { super(message, options); diff --git a/src/error.ts b/src/error.ts index 8c9f495626d..70bf166583d 100644 --- a/src/error.ts +++ b/src/error.ts @@ -108,6 +108,10 @@ export interface ErrorDescription extends Document { errInfo?: Document; } +interface OptionsWithCause { + cause?: Error; +} + function isAggregateError(e: Error): e is Error & { errors: Error[] } { return 'errors' in e && Array.isArray(e.errors); } @@ -130,16 +134,10 @@ export class MongoError extends Error { code?: number | string; topologyVersion?: TopologyVersion; connectionGeneration?: number; - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - cause?: Error; // depending on the node version, this may or may not exist on the base - - constructor(message: string | Error) { - super(MongoError.buildErrorMessage(message)); - if (message instanceof Error) { - this.cause = message; - } + /** @internal */ + constructor(message: string | Error, options?: OptionsWithCause) { + super(MongoError.buildErrorMessage(message), options); this[kErrorLabels] = new Set(); } @@ -198,6 +196,7 @@ export class MongoServerError extends MongoError { ok?: number; [key: string]: any; + /** @internal */ constructor(message: ErrorDescription) { super(message.message || message.errmsg || message.$err || 'n/a'); if (message.errorLabels) { @@ -222,8 +221,9 @@ export class MongoServerError extends MongoError { * @category Error */ export class MongoDriverError extends MongoError { - constructor(message: string) { - super(message); + /** @internal */ + constructor(message: string, options?: OptionsWithCause) { + super(message, options); } override get name(): string { @@ -242,8 +242,9 @@ export class MongoDriverError extends MongoError { */ export class MongoAPIError extends MongoDriverError { - constructor(message: string) { - super(message); + /** @internal */ + constructor(message: string, options?: OptionsWithCause) { + super(message, options); } override get name(): string { @@ -262,8 +263,9 @@ export class MongoAPIError extends MongoDriverError { * @category Error */ export class MongoRuntimeError extends MongoDriverError { - constructor(message: string) { - super(message); + /** @internal */ + constructor(message: string, options?: OptionsWithCause) { + super(message, options); } override get name(): string { @@ -279,8 +281,12 @@ export class MongoRuntimeError extends MongoDriverError { * @category Error */ export class MongoBatchReExecutionError extends MongoAPIError { - constructor(message = 'This batch has already been executed, create new batch to execute') { - super(message); + /** @internal */ + constructor( + message = 'This batch has already been executed, create new batch to execute', + options?: OptionsWithCause + ) { + super(message, options); } override get name(): string { @@ -296,8 +302,9 @@ export class MongoBatchReExecutionError extends MongoAPIError { * @category Error */ export class MongoDecompressionError extends MongoRuntimeError { - constructor(message: string) { - super(message); + /** @internal */ + constructor(message: string, options?: OptionsWithCause) { + super(message, options); } override get name(): string { @@ -313,8 +320,9 @@ export class MongoDecompressionError extends MongoRuntimeError { * @category Error */ export class MongoNotConnectedError extends MongoAPIError { - constructor(message: string) { - super(message); + /** @internal */ + constructor(message: string, options?: OptionsWithCause) { + super(message, options); } override get name(): string { @@ -330,8 +338,9 @@ export class MongoNotConnectedError extends MongoAPIError { * @category Error */ export class MongoTransactionError extends MongoAPIError { - constructor(message: string) { - super(message); + /** @internal */ + constructor(message: string, options?: OptionsWithCause) { + super(message, options); } override get name(): string { @@ -347,8 +356,9 @@ export class MongoTransactionError extends MongoAPIError { * @category Error */ export class MongoExpiredSessionError extends MongoAPIError { - constructor(message = 'Cannot use a session that has ended') { - super(message); + /** @internal */ + constructor(message = 'Cannot use a session that has ended', options?: OptionsWithCause) { + super(message, options); } override get name(): string { @@ -364,8 +374,9 @@ export class MongoExpiredSessionError extends MongoAPIError { * @category Error */ export class MongoKerberosError extends MongoRuntimeError { - constructor(message: string) { - super(message); + /** @internal */ + constructor(message: string, options?: OptionsWithCause) { + super(message, options); } override get name(): string { @@ -381,8 +392,9 @@ export class MongoKerberosError extends MongoRuntimeError { * @category Error */ export class MongoAWSError extends MongoRuntimeError { - constructor(message: string) { - super(message); + /** @internal */ + constructor(message: string, options?: OptionsWithCause) { + super(message, options); } override get name(): string { @@ -398,8 +410,9 @@ export class MongoAWSError extends MongoRuntimeError { * @category Error */ export class MongoAzureError extends MongoRuntimeError { - constructor(message: string) { - super(message); + /** @internal */ + constructor(message: string, options?: OptionsWithCause) { + super(message, options); } override get name(): string { @@ -414,8 +427,9 @@ export class MongoAzureError extends MongoRuntimeError { * @category Error */ export class MongoChangeStreamError extends MongoRuntimeError { - constructor(message: string) { - super(message); + /** @internal */ + constructor(message: string, options?: OptionsWithCause) { + super(message, options); } override get name(): string { @@ -430,8 +444,12 @@ export class MongoChangeStreamError extends MongoRuntimeError { * @category Error */ export class MongoTailableCursorError extends MongoAPIError { - constructor(message = 'Tailable cursor does not support this operation') { - super(message); + /** @internal */ + constructor( + message = 'Tailable cursor does not support this operation', + options?: OptionsWithCause + ) { + super(message, options); } override get name(): string { @@ -445,8 +463,9 @@ export class MongoTailableCursorError extends MongoAPIError { * @category Error */ export class MongoGridFSStreamError extends MongoRuntimeError { - constructor(message: string) { - super(message); + /** @internal */ + constructor(message: string, options?: OptionsWithCause) { + super(message, options); } override get name(): string { @@ -462,8 +481,9 @@ export class MongoGridFSStreamError extends MongoRuntimeError { * @category Error */ export class MongoGridFSChunkError extends MongoRuntimeError { - constructor(message: string) { - super(message); + /** @internal */ + constructor(message: string, options?: OptionsWithCause) { + super(message, options); } override get name(): string { @@ -488,8 +508,9 @@ export class MongoGridFSChunkError extends MongoRuntimeError { * @category Error */ export class MongoUnexpectedServerResponseError extends MongoRuntimeError { - constructor(message: string) { - super(message); + /** @internal */ + constructor(message: string, options?: OptionsWithCause) { + super(message, options); } override get name(): string { @@ -505,8 +526,9 @@ export class MongoUnexpectedServerResponseError extends MongoRuntimeError { * @category Error */ export class MongoCursorInUseError extends MongoAPIError { - constructor(message = 'Cursor is already initialized') { - super(message); + /** @internal */ + constructor(message = 'Cursor is already initialized', options?: OptionsWithCause) { + super(message, options); } override get name(): string { @@ -522,8 +544,9 @@ export class MongoCursorInUseError extends MongoAPIError { * @category Error */ export class MongoServerClosedError extends MongoAPIError { - constructor(message = 'Server is closed') { - super(message); + /** @internal */ + constructor(message = 'Server is closed', options?: OptionsWithCause) { + super(message, options); } override get name(): string { @@ -538,8 +561,9 @@ export class MongoServerClosedError extends MongoAPIError { * @category Error */ export class MongoCursorExhaustedError extends MongoAPIError { - constructor(message?: string) { - super(message || 'Cursor is exhausted'); + /** @internal */ + constructor(message?: string, options?: OptionsWithCause) { + super(message || 'Cursor is exhausted', options); } override get name(): string { @@ -555,8 +579,9 @@ export class MongoCursorExhaustedError extends MongoAPIError { * @category Error */ export class MongoTopologyClosedError extends MongoAPIError { - constructor(message = 'Topology is closed') { - super(message); + /** @internal */ + constructor(message = 'Topology is closed', options?: OptionsWithCause) { + super(message, options); } override get name(): string { @@ -585,6 +610,7 @@ export class MongoNetworkError extends MongoError { /** @internal */ [kBeforeHandshake]?: boolean; + /** @internal */ constructor(message: string | Error, options?: MongoNetworkErrorOptions) { super(message); @@ -607,6 +633,7 @@ export class MongoNetworkError extends MongoError { * mongodb-client-encryption has a dependency on this error with an instanceof check */ export class MongoNetworkTimeoutError extends MongoNetworkError { + /** @internal */ constructor(message: string, options?: MongoNetworkErrorOptions) { super(message, options); } @@ -622,8 +649,9 @@ export class MongoNetworkTimeoutError extends MongoNetworkError { * @category Error */ export class MongoParseError extends MongoDriverError { - constructor(message: string) { - super(message); + /** @internal */ + constructor(message: string, options?: OptionsWithCause) { + super(message, options); } override get name(): string { @@ -640,8 +668,9 @@ export class MongoParseError extends MongoDriverError { * @category Error */ export class MongoInvalidArgumentError extends MongoAPIError { - constructor(message: string) { - super(message); + /** @internal */ + constructor(message: string, options?: OptionsWithCause) { + super(message, options); } override get name(): string { @@ -658,8 +687,9 @@ export class MongoInvalidArgumentError extends MongoAPIError { * @category Error */ export class MongoCompatibilityError extends MongoAPIError { - constructor(message: string) { - super(message); + /** @internal */ + constructor(message: string, options?: OptionsWithCause) { + super(message, options); } override get name(): string { @@ -676,8 +706,9 @@ export class MongoCompatibilityError extends MongoAPIError { * @category Error */ export class MongoMissingCredentialsError extends MongoAPIError { - constructor(message: string) { - super(message); + /** @internal */ + constructor(message: string, options?: OptionsWithCause) { + super(message, options); } override get name(): string { @@ -692,9 +723,9 @@ export class MongoMissingCredentialsError extends MongoAPIError { * @category Error */ export class MongoMissingDependencyError extends MongoAPIError { - constructor(message: string, { cause }: { cause?: Error } = {}) { - super(message); - if (cause) this.cause = cause; + /** @internal */ + constructor(message: string, options: OptionsWithCause) { + super(message, options); } override get name(): string { @@ -710,11 +741,12 @@ export class MongoSystemError extends MongoError { /** An optional reason context, such as an error saved during flow of monitoring and selecting servers */ reason?: TopologyDescription; - constructor(message: string, reason: TopologyDescription) { + /** @internal */ + constructor(message: string, reason: TopologyDescription, options?: OptionsWithCause) { if (reason && reason.error) { - super(reason.error.message || reason.error); + super(reason.error.message || reason.error, options); } else { - super(message); + super(message, options); } if (reason) { @@ -735,8 +767,9 @@ export class MongoSystemError extends MongoError { * @category Error */ export class MongoServerSelectionError extends MongoSystemError { - constructor(message: string, reason: TopologyDescription) { - super(message, reason); + /** @internal */ + constructor(message: string, reason: TopologyDescription, options?: OptionsWithCause) { + super(message, reason, options); } override get name(): string { @@ -766,6 +799,8 @@ export class MongoWriteConcernError extends MongoServerError { /** The result document (provided if ok: 1) */ result?: Document; + // TODO + /** @internal */ constructor(message: ErrorDescription, result?: Document) { if (result && Array.isArray(result.errorLabels)) { message.errorLabels = result.errorLabels; From d50431730721d430ce903459d9b4536f32dd828f Mon Sep 17 00:00:00 2001 From: Warren James Date: Mon, 7 Aug 2023 14:29:43 -0400 Subject: [PATCH 02/37] fix(NODE-5484): only remove unnecessary options --- src/error.ts | 111 ++++++++++++++++++++++++--------------------------- 1 file changed, 52 insertions(+), 59 deletions(-) diff --git a/src/error.ts b/src/error.ts index 70bf166583d..9e8bb11ad3e 100644 --- a/src/error.ts +++ b/src/error.ts @@ -222,8 +222,8 @@ export class MongoServerError extends MongoError { */ export class MongoDriverError extends MongoError { /** @internal */ - constructor(message: string, options?: OptionsWithCause) { - super(message, options); + constructor(message: string) { + super(message); } override get name(): string { @@ -243,8 +243,8 @@ export class MongoDriverError extends MongoError { export class MongoAPIError extends MongoDriverError { /** @internal */ - constructor(message: string, options?: OptionsWithCause) { - super(message, options); + constructor(message: string) { + super(message); } override get name(): string { @@ -264,8 +264,8 @@ export class MongoAPIError extends MongoDriverError { */ export class MongoRuntimeError extends MongoDriverError { /** @internal */ - constructor(message: string, options?: OptionsWithCause) { - super(message, options); + constructor(message: string) { + super(message); } override get name(): string { @@ -282,11 +282,8 @@ export class MongoRuntimeError extends MongoDriverError { */ export class MongoBatchReExecutionError extends MongoAPIError { /** @internal */ - constructor( - message = 'This batch has already been executed, create new batch to execute', - options?: OptionsWithCause - ) { - super(message, options); + constructor(message = 'This batch has already been executed, create new batch to execute') { + super(message); } override get name(): string { @@ -303,8 +300,8 @@ export class MongoBatchReExecutionError extends MongoAPIError { */ export class MongoDecompressionError extends MongoRuntimeError { /** @internal */ - constructor(message: string, options?: OptionsWithCause) { - super(message, options); + constructor(message: string) { + super(message); } override get name(): string { @@ -321,8 +318,8 @@ export class MongoDecompressionError extends MongoRuntimeError { */ export class MongoNotConnectedError extends MongoAPIError { /** @internal */ - constructor(message: string, options?: OptionsWithCause) { - super(message, options); + constructor(message: string) { + super(message); } override get name(): string { @@ -339,8 +336,8 @@ export class MongoNotConnectedError extends MongoAPIError { */ export class MongoTransactionError extends MongoAPIError { /** @internal */ - constructor(message: string, options?: OptionsWithCause) { - super(message, options); + constructor(message: string) { + super(message); } override get name(): string { @@ -357,8 +354,8 @@ export class MongoTransactionError extends MongoAPIError { */ export class MongoExpiredSessionError extends MongoAPIError { /** @internal */ - constructor(message = 'Cannot use a session that has ended', options?: OptionsWithCause) { - super(message, options); + constructor(message = 'Cannot use a session that has ended') { + super(message); } override get name(): string { @@ -375,8 +372,8 @@ export class MongoExpiredSessionError extends MongoAPIError { */ export class MongoKerberosError extends MongoRuntimeError { /** @internal */ - constructor(message: string, options?: OptionsWithCause) { - super(message, options); + constructor(message: string) { + super(message); } override get name(): string { @@ -393,8 +390,8 @@ export class MongoKerberosError extends MongoRuntimeError { */ export class MongoAWSError extends MongoRuntimeError { /** @internal */ - constructor(message: string, options?: OptionsWithCause) { - super(message, options); + constructor(message: string) { + super(message); } override get name(): string { @@ -411,8 +408,8 @@ export class MongoAWSError extends MongoRuntimeError { */ export class MongoAzureError extends MongoRuntimeError { /** @internal */ - constructor(message: string, options?: OptionsWithCause) { - super(message, options); + constructor(message: string) { + super(message); } override get name(): string { @@ -428,8 +425,8 @@ export class MongoAzureError extends MongoRuntimeError { */ export class MongoChangeStreamError extends MongoRuntimeError { /** @internal */ - constructor(message: string, options?: OptionsWithCause) { - super(message, options); + constructor(message: string) { + super(message); } override get name(): string { @@ -445,11 +442,8 @@ export class MongoChangeStreamError extends MongoRuntimeError { */ export class MongoTailableCursorError extends MongoAPIError { /** @internal */ - constructor( - message = 'Tailable cursor does not support this operation', - options?: OptionsWithCause - ) { - super(message, options); + constructor(message = 'Tailable cursor does not support this operation') { + super(message); } override get name(): string { @@ -464,8 +458,8 @@ export class MongoTailableCursorError extends MongoAPIError { */ export class MongoGridFSStreamError extends MongoRuntimeError { /** @internal */ - constructor(message: string, options?: OptionsWithCause) { - super(message, options); + constructor(message: string) { + super(message); } override get name(): string { @@ -482,8 +476,8 @@ export class MongoGridFSStreamError extends MongoRuntimeError { */ export class MongoGridFSChunkError extends MongoRuntimeError { /** @internal */ - constructor(message: string, options?: OptionsWithCause) { - super(message, options); + constructor(message: string) { + super(message); } override get name(): string { @@ -509,8 +503,8 @@ export class MongoGridFSChunkError extends MongoRuntimeError { */ export class MongoUnexpectedServerResponseError extends MongoRuntimeError { /** @internal */ - constructor(message: string, options?: OptionsWithCause) { - super(message, options); + constructor(message: string) { + super(message); } override get name(): string { @@ -527,8 +521,8 @@ export class MongoUnexpectedServerResponseError extends MongoRuntimeError { */ export class MongoCursorInUseError extends MongoAPIError { /** @internal */ - constructor(message = 'Cursor is already initialized', options?: OptionsWithCause) { - super(message, options); + constructor(message = 'Cursor is already initialized') { + super(message); } override get name(): string { @@ -545,8 +539,8 @@ export class MongoCursorInUseError extends MongoAPIError { */ export class MongoServerClosedError extends MongoAPIError { /** @internal */ - constructor(message = 'Server is closed', options?: OptionsWithCause) { - super(message, options); + constructor(message = 'Server is closed') { + super(message); } override get name(): string { @@ -562,8 +556,8 @@ export class MongoServerClosedError extends MongoAPIError { */ export class MongoCursorExhaustedError extends MongoAPIError { /** @internal */ - constructor(message?: string, options?: OptionsWithCause) { - super(message || 'Cursor is exhausted', options); + constructor(message?: string) { + super(message || 'Cursor is exhausted'); } override get name(): string { @@ -580,8 +574,8 @@ export class MongoCursorExhaustedError extends MongoAPIError { */ export class MongoTopologyClosedError extends MongoAPIError { /** @internal */ - constructor(message = 'Topology is closed', options?: OptionsWithCause) { - super(message, options); + constructor(message = 'Topology is closed') { + super(message); } override get name(): string { @@ -650,8 +644,8 @@ export class MongoNetworkTimeoutError extends MongoNetworkError { */ export class MongoParseError extends MongoDriverError { /** @internal */ - constructor(message: string, options?: OptionsWithCause) { - super(message, options); + constructor(message: string) { + super(message); } override get name(): string { @@ -669,8 +663,8 @@ export class MongoParseError extends MongoDriverError { */ export class MongoInvalidArgumentError extends MongoAPIError { /** @internal */ - constructor(message: string, options?: OptionsWithCause) { - super(message, options); + constructor(message: string) { + super(message); } override get name(): string { @@ -688,8 +682,8 @@ export class MongoInvalidArgumentError extends MongoAPIError { */ export class MongoCompatibilityError extends MongoAPIError { /** @internal */ - constructor(message: string, options?: OptionsWithCause) { - super(message, options); + constructor(message: string) { + super(message); } override get name(): string { @@ -707,8 +701,8 @@ export class MongoCompatibilityError extends MongoAPIError { */ export class MongoMissingCredentialsError extends MongoAPIError { /** @internal */ - constructor(message: string, options?: OptionsWithCause) { - super(message, options); + constructor(message: string) { + super(message); } override get name(): string { @@ -724,8 +718,8 @@ export class MongoMissingCredentialsError extends MongoAPIError { */ export class MongoMissingDependencyError extends MongoAPIError { /** @internal */ - constructor(message: string, options: OptionsWithCause) { - super(message, options); + constructor(message: string) { + super(message); } override get name(): string { @@ -768,8 +762,8 @@ export class MongoSystemError extends MongoError { */ export class MongoServerSelectionError extends MongoSystemError { /** @internal */ - constructor(message: string, reason: TopologyDescription, options?: OptionsWithCause) { - super(message, reason, options); + constructor(message: string, reason: TopologyDescription) { + super(message, reason); } override get name(): string { @@ -799,7 +793,6 @@ export class MongoWriteConcernError extends MongoServerError { /** The result document (provided if ok: 1) */ result?: Document; - // TODO /** @internal */ constructor(message: ErrorDescription, result?: Document) { if (result && Array.isArray(result.errorLabels)) { From d2012c5a1cdf9bf0919721bdd56e0f8d4d7bf927 Mon Sep 17 00:00:00 2001 From: Warren James Date: Mon, 7 Aug 2023 14:51:30 -0400 Subject: [PATCH 03/37] fix(NODE-5484): make constructors internal --- src/bulk/common.ts | 2 +- src/cmap/errors.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/bulk/common.ts b/src/bulk/common.ts index c9ab3bbcd80..95005b01f35 100644 --- a/src/bulk/common.ts +++ b/src/bulk/common.ts @@ -598,7 +598,7 @@ export class MongoBulkWriteError extends MongoServerError { writeErrors: OneOrMore = []; err?: WriteConcernError; - /** Creates a new MongoBulkWriteError */ + /** @internal Creates a new MongoBulkWriteError */ constructor( error: | { message: string; code: number; writeErrors?: WriteError[] } diff --git a/src/cmap/errors.ts b/src/cmap/errors.ts index f6d2ed58880..b6916f77665 100644 --- a/src/cmap/errors.ts +++ b/src/cmap/errors.ts @@ -9,6 +9,7 @@ export class PoolClosedError extends MongoDriverError { /** The address of the connection pool */ address: string; + /** @internal */ constructor(pool: ConnectionPool) { super('Attempted to check out a connection from closed connection pool'); this.address = pool.address; @@ -27,6 +28,7 @@ export class PoolClearedError extends MongoNetworkError { /** The address of the connection pool */ address: string; + /** @internal */ constructor(pool: ConnectionPool, message?: string) { const errorMessage = message ? message @@ -47,6 +49,7 @@ export class PoolClearedError extends MongoNetworkError { * @category Error */ export class PoolClearedOnNetworkError extends PoolClearedError { + /** @internal */ constructor(pool: ConnectionPool) { super(pool, `Connection to ${pool.address} interrupted due to server monitor timeout`); } @@ -64,6 +67,7 @@ export class WaitQueueTimeoutError extends MongoDriverError { /** The address of the connection pool */ address: string; + /** @internal */ constructor(message: string, address: string) { super(message); this.address = address; From ea5ea727645dd97e3eea4c6d5c1b36dd7c4f7dbf Mon Sep 17 00:00:00 2001 From: Warren James Date: Mon, 7 Aug 2023 14:51:58 -0400 Subject: [PATCH 04/37] test(NODE-5484): add unit tests to check that MongoCrypt Errors subclass MongoError --- .../client-side-encryption/errors.test.ts | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 test/unit/client-side-encryption/errors.test.ts diff --git a/test/unit/client-side-encryption/errors.test.ts b/test/unit/client-side-encryption/errors.test.ts new file mode 100644 index 00000000000..f586be7cad9 --- /dev/null +++ b/test/unit/client-side-encryption/errors.test.ts @@ -0,0 +1,37 @@ +/* eslint-disable @typescript-eslint/no-restricted-imports */ +import { expect } from 'chai'; + +import { + MongoCryptAzureKMSRequestError, + MongoCryptCreateDataKeyError, + MongoCryptCreateEncryptedCollectionError, + MongoCryptError, + MongoCryptInvalidArgumentError +} from '../../../src/client-side-encryption/errors'; +import { MongoError } from '../../mongodb'; + +describe('ClientEncryption', function () { + describe('Errors', function () { + const errors = [ + new MongoCryptAzureKMSRequestError(''), + new MongoCryptCreateDataKeyError({ + encryptedFields: {}, + cause: new Error() + }), + new MongoCryptCreateEncryptedCollectionError({ + encryptedFields: {}, + cause: new Error() + }), + new MongoCryptError(''), + new MongoCryptInvalidArgumentError('') + ]; + + for (const err of errors) { + describe(err.name, function () { + it('is subclass of MongoError', function () { + expect(err).to.be.instanceOf(MongoError); + }); + }); + } + }); +}); From 53491bd8dbfcc385836aec1e2ffdf447f1ecfaf8 Mon Sep 17 00:00:00 2001 From: Warren James Date: Mon, 7 Aug 2023 15:37:29 -0400 Subject: [PATCH 05/37] docs(NODE-5484): start docs update --- etc/notes/errors.md | 46 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/etc/notes/errors.md b/etc/notes/errors.md index 03c47e73739..b5cd1fd8b4f 100644 --- a/etc/notes/errors.md +++ b/etc/notes/errors.md @@ -28,12 +28,18 @@ - [`MongoServerClosedError`](#MongoServerClosedError-1) - [`MongoNetworkError`](#MongoNetworkError-1) - [`MongoNetworkTimeoutError`](#MongoNetworkTimeoutError-1) + - [`MongoCryptError`](#MongoCryptError-1) + - [`MongoCryptInvalidArgumentError`](#MongoCryptError-1) + - [`MongoCryptCreateDataKeyError`](#MongoCryptCreateDataKeyError-1) + - [`MongoCryptCreateEncryptedCollectionError`](#MongoCryptCreateEncryptedCollectionError-1) + - [`MongoCryptCreateAzureKMSRequestError`](#MongoCryptCreateAzureKMSRequestError-1) + - [`MongoCryptCreateAzureKMSRequestNetworkTimeoutError`](#MongoCryptCreateAzureKMSRequestNetworkTimeoutError-1) ## Errors All errors are derived from the `MongoError` class which should **never** be instantiated. -There are four main error classes which stem from `MongoError`: `MongoDriverError`, -`MongoNetworkError`, `MongoServerError`, and `MongoSystemError`. +There are five main error classes which stem from `MongoError`: `MongoDriverError`, +`MongoNetworkError`, `MongoServerError`, `MongoCryptError` and `MongoSystemError`. ### `MongoError` @@ -46,6 +52,12 @@ graph TD MongoError --- MongoNetworkError MongoError --- MongoServerError MongoError --- MongoSystemError + MongoError --- MongoCryptError + MongoCryptError --- MongoCryptInvalidArgumentError + MongoCryptError --- MongoCryptCreateDataKeyError + MongoCryptError --- MongoCryptCreateEncryptedCollectionError + MongoCryptError --- MongoCryptCreateAzureKMSRequestError + MongoCryptError --- MongoCryptCreateAzureKMSRequestNetworkTimeoutError MongoDriverError --- MongoAPIError MongoDriverError --- MongoRuntimeError @@ -55,14 +67,28 @@ linkStyle 2 stroke:#116149 linkStyle 3 stroke:#116149 linkStyle 4 stroke:#116149 linkStyle 5 stroke:#116149 +linkStyle 6 stroke:#116149 +linkStyle 7 stroke:#116149 +linkStyle 8 stroke:#116149 +linkStyle 9 stroke:#116149 +linkStyle 10 stroke:#116149 +linkStyle 11 stroke:#116149 style MongoError fill:#13aa52,stroke:#21313c,color:#FAFBFC +style MongoCryptError fill:#13aa52,stroke:#21313c,color:#FAFBFC style MongoSystemError fill:#13aa52,stroke:#21313c,color:#FAFBFC style MongoNetworkError fill:#13aa52,stroke:#21313c,color:#FAFBFC style MongoServerError fill:#13aa52,stroke:#21313c,color:#FAFBFC style MongoDriverError fill:#13aa52,stroke:#21313c,color:#FAFBFC style MongoAPIError fill:#13aa52,stroke:#21313c,color:#FAFBFC style MongoRuntimeError fill:#13aa52,stroke:#21313c,color:#FAFBFC + + +style MongoCryptCreateDataKeyError fill:#13aa52,stroke:#21313c,color:#FAFBFC +style MongoCryptCreateEncryptedCollectionError fill:#13aa52,stroke:#21313c,color:#FAFBFC +style MongoCryptInvalidArgumentError fill:#13aa52,stroke:#21313c,color:#FAFBFC +style MongoCryptCreateAzureKMSRequestError fill:#13aa52,stroke:#21313c,color:#FAFBFC +style MongoCryptCreateAzureKMSRequestNetworkTimeoutError fill:#13aa52,stroke:#21313c,color:#FAFBFC ``` Children of `MongoError` include: @@ -71,6 +97,7 @@ Children of `MongoError` include: - [`MongoNetworkError`](#MongoNetworkError) - [`MongoServerError`](#MongoServerError) - [`MongoSystemError`](#MongoSystemError) +- [`MongoCryptError`](#MongoCryptError) ### `MongoDriverError` @@ -144,6 +171,21 @@ These are errors which originate from faulty environment setup. - #### MongoServerSelectionError - Thrown when the driver fails to select a server to complete an operation +### `MongoCryptError` + +These are errors thrown from the `mongodb-client-encryption` bindings + +- #### MongoCryptInvalidArgumentError + - Thrown when +- #### MongoCryptInvalidCreateDataKeyError + - Thrown when +- #### MongoCryptInvalidCreateEncryptedCollectionError + - Thrown when +- #### MongoCryptInvalidCreateAzureKMSRequestError + - Thrown when +- #### MongoCryptInvalidCreateAzureKMSRequestNetworkTimeoutError + - Thrown when + ## Test Plan The test plan consists of a series of prose tests. From 55f487c68f2fd0fde5aaaeefc6f2dfaeacfd7b17 Mon Sep 17 00:00:00 2001 From: Warren James Date: Mon, 7 Aug 2023 16:06:28 -0400 Subject: [PATCH 06/37] fix(NODE-5484): remove unneeded type --- src/error.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/error.ts b/src/error.ts index 9e8bb11ad3e..636ad988691 100644 --- a/src/error.ts +++ b/src/error.ts @@ -108,10 +108,6 @@ export interface ErrorDescription extends Document { errInfo?: Document; } -interface OptionsWithCause { - cause?: Error; -} - function isAggregateError(e: Error): e is Error & { errors: Error[] } { return 'errors' in e && Array.isArray(e.errors); } @@ -136,7 +132,7 @@ export class MongoError extends Error { connectionGeneration?: number; /** @internal */ - constructor(message: string | Error, options?: OptionsWithCause) { + constructor(message: string | Error, options?: { cause?: Error }) { super(MongoError.buildErrorMessage(message), options); this[kErrorLabels] = new Set(); } @@ -736,7 +732,7 @@ export class MongoSystemError extends MongoError { reason?: TopologyDescription; /** @internal */ - constructor(message: string, reason: TopologyDescription, options?: OptionsWithCause) { + constructor(message: string, reason: TopologyDescription, options?: { cause?: Error }) { if (reason && reason.error) { super(reason.error.message || reason.error, options); } else { From ccb0866dfe9efb4a42056c8742080ef2379901b3 Mon Sep 17 00:00:00 2001 From: Warren James Date: Mon, 7 Aug 2023 16:06:45 -0400 Subject: [PATCH 07/37] docs(NODE-5484): update docs --- etc/notes/errors.md | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/etc/notes/errors.md b/etc/notes/errors.md index b5cd1fd8b4f..0970497ed91 100644 --- a/etc/notes/errors.md +++ b/etc/notes/errors.md @@ -18,6 +18,7 @@ - [`MongoNetworkError`](#MongoNetworkError) - [`MongoServerError`](#MongoServerError) - [`MongoSystemError`](#MongoSystemError) + - [`MongoCryptError`](#MongoCryptError) - [Test Plan](#Test-Plan) - [`MongoAPIError`](#MongoAPIError-1) - [`MongoInvalidArgumentError`](#MongoInvalidArgumentError-1) @@ -28,12 +29,6 @@ - [`MongoServerClosedError`](#MongoServerClosedError-1) - [`MongoNetworkError`](#MongoNetworkError-1) - [`MongoNetworkTimeoutError`](#MongoNetworkTimeoutError-1) - - [`MongoCryptError`](#MongoCryptError-1) - - [`MongoCryptInvalidArgumentError`](#MongoCryptError-1) - - [`MongoCryptCreateDataKeyError`](#MongoCryptCreateDataKeyError-1) - - [`MongoCryptCreateEncryptedCollectionError`](#MongoCryptCreateEncryptedCollectionError-1) - - [`MongoCryptCreateAzureKMSRequestError`](#MongoCryptCreateAzureKMSRequestError-1) - - [`MongoCryptCreateAzureKMSRequestNetworkTimeoutError`](#MongoCryptCreateAzureKMSRequestNetworkTimeoutError-1) ## Errors @@ -53,11 +48,6 @@ graph TD MongoError --- MongoServerError MongoError --- MongoSystemError MongoError --- MongoCryptError - MongoCryptError --- MongoCryptInvalidArgumentError - MongoCryptError --- MongoCryptCreateDataKeyError - MongoCryptError --- MongoCryptCreateEncryptedCollectionError - MongoCryptError --- MongoCryptCreateAzureKMSRequestError - MongoCryptError --- MongoCryptCreateAzureKMSRequestNetworkTimeoutError MongoDriverError --- MongoAPIError MongoDriverError --- MongoRuntimeError @@ -82,13 +72,6 @@ style MongoServerError fill:#13aa52,stroke:#21313c,color:#FAFBFC style MongoDriverError fill:#13aa52,stroke:#21313c,color:#FAFBFC style MongoAPIError fill:#13aa52,stroke:#21313c,color:#FAFBFC style MongoRuntimeError fill:#13aa52,stroke:#21313c,color:#FAFBFC - - -style MongoCryptCreateDataKeyError fill:#13aa52,stroke:#21313c,color:#FAFBFC -style MongoCryptCreateEncryptedCollectionError fill:#13aa52,stroke:#21313c,color:#FAFBFC -style MongoCryptInvalidArgumentError fill:#13aa52,stroke:#21313c,color:#FAFBFC -style MongoCryptCreateAzureKMSRequestError fill:#13aa52,stroke:#21313c,color:#FAFBFC -style MongoCryptCreateAzureKMSRequestNetworkTimeoutError fill:#13aa52,stroke:#21313c,color:#FAFBFC ``` Children of `MongoError` include: @@ -176,15 +159,15 @@ These are errors which originate from faulty environment setup. These are errors thrown from the `mongodb-client-encryption` bindings - #### MongoCryptInvalidArgumentError - - Thrown when + - Thrown when an invalid argument has been provided to an encryption API - #### MongoCryptInvalidCreateDataKeyError - - Thrown when + - Thrown when `ClientEncryption.createEncryptedCollection()` failed to create data keys - #### MongoCryptInvalidCreateEncryptedCollectionError - - Thrown when + - Thrown when `ClientEncryption.createEncryptedCollection()` failed to create a collection - #### MongoCryptInvalidCreateAzureKMSRequestError - - Thrown when -- #### MongoCryptInvalidCreateAzureKMSRequestNetworkTimeoutError - - Thrown when + - Thrown when `mongodb-client-encryption` failed to auto-refresh Azure KMS credentials +- #### MongoCryptKMSRequestNetworkTimeoutError + - Thrown when `mongodb-client-encryption` times out when fetching KMS credentials ## Test Plan From be7c2f9c0041f5c02af9ae00d0c2a1a5e88f06d3 Mon Sep 17 00:00:00 2001 From: Warren James Date: Mon, 7 Aug 2023 16:08:30 -0400 Subject: [PATCH 08/37] docs(NODE-5484): fix diagram --- etc/notes/errors.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/etc/notes/errors.md b/etc/notes/errors.md index 0970497ed91..0a6627d2998 100644 --- a/etc/notes/errors.md +++ b/etc/notes/errors.md @@ -59,10 +59,6 @@ linkStyle 4 stroke:#116149 linkStyle 5 stroke:#116149 linkStyle 6 stroke:#116149 linkStyle 7 stroke:#116149 -linkStyle 8 stroke:#116149 -linkStyle 9 stroke:#116149 -linkStyle 10 stroke:#116149 -linkStyle 11 stroke:#116149 style MongoError fill:#13aa52,stroke:#21313c,color:#FAFBFC style MongoCryptError fill:#13aa52,stroke:#21313c,color:#FAFBFC From 85b02a54a21b7e12ea26f5b47e841e32ef33351d Mon Sep 17 00:00:00 2001 From: Warren James Date: Mon, 7 Aug 2023 16:11:03 -0400 Subject: [PATCH 09/37] docs(NODE-5484): fix diagram --- etc/notes/errors.md | 1 - 1 file changed, 1 deletion(-) diff --git a/etc/notes/errors.md b/etc/notes/errors.md index 0a6627d2998..8c318a4ba69 100644 --- a/etc/notes/errors.md +++ b/etc/notes/errors.md @@ -58,7 +58,6 @@ linkStyle 3 stroke:#116149 linkStyle 4 stroke:#116149 linkStyle 5 stroke:#116149 linkStyle 6 stroke:#116149 -linkStyle 7 stroke:#116149 style MongoError fill:#13aa52,stroke:#21313c,color:#FAFBFC style MongoCryptError fill:#13aa52,stroke:#21313c,color:#FAFBFC From 4b1ad15c41d81f013798a93e0f969e5beed8048e Mon Sep 17 00:00:00 2001 From: Warren James Date: Mon, 7 Aug 2023 16:19:15 -0400 Subject: [PATCH 10/37] docs(NODE-5484): clean up mermaid code --- etc/notes/errors.md | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/etc/notes/errors.md b/etc/notes/errors.md index 8c318a4ba69..4dac07b5261 100644 --- a/etc/notes/errors.md +++ b/etc/notes/errors.md @@ -42,31 +42,18 @@ The base class from which all errors in the Node driver subclass. `MongoError` should **never** be be directly instantiated. ```mermaid + graph TD - MongoError --- MongoDriverError - MongoError --- MongoNetworkError - MongoError --- MongoServerError - MongoError --- MongoSystemError - MongoError --- MongoCryptError - MongoDriverError --- MongoAPIError - MongoDriverError --- MongoRuntimeError - -linkStyle 0 stroke:#116149 -linkStyle 1 stroke:#116149 -linkStyle 2 stroke:#116149 -linkStyle 3 stroke:#116149 -linkStyle 4 stroke:#116149 -linkStyle 5 stroke:#116149 -linkStyle 6 stroke:#116149 - -style MongoError fill:#13aa52,stroke:#21313c,color:#FAFBFC -style MongoCryptError fill:#13aa52,stroke:#21313c,color:#FAFBFC -style MongoSystemError fill:#13aa52,stroke:#21313c,color:#FAFBFC -style MongoNetworkError fill:#13aa52,stroke:#21313c,color:#FAFBFC -style MongoServerError fill:#13aa52,stroke:#21313c,color:#FAFBFC -style MongoDriverError fill:#13aa52,stroke:#21313c,color:#FAFBFC -style MongoAPIError fill:#13aa52,stroke:#21313c,color:#FAFBFC -style MongoRuntimeError fill:#13aa52,stroke:#21313c,color:#FAFBFC + MongoError:::node --- MongoDriverError + MongoError:::node --- MongoNetworkError + MongoError:::node --- MongoServerError + MongoError:::node --- MongoSystemError + MongoError:::node --- MongoCryptError + MongoDriverError:::node --- MongoAPIError + MongoDriverError:::node --- MongoRuntimeError + +linkStyle 0,1,2,3,4,5,6 stroke:#116149 +classDef node fill:#13aa52,stroke:#21313c,color:#FAFBFC ``` Children of `MongoError` include: From aac86bc70c18b0ce8c2e7176d3361c3ae20eca30 Mon Sep 17 00:00:00 2001 From: Warren James Date: Mon, 7 Aug 2023 16:36:46 -0400 Subject: [PATCH 11/37] fix(NODE-5484): fix inheritance --- src/error.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/error.ts b/src/error.ts index 636ad988691..2965f79ff38 100644 --- a/src/error.ts +++ b/src/error.ts @@ -218,8 +218,8 @@ export class MongoServerError extends MongoError { */ export class MongoDriverError extends MongoError { /** @internal */ - constructor(message: string) { - super(message); + constructor(message: string, options?: { cause?: Error }) { + super(message, options); } override get name(): string { @@ -239,8 +239,8 @@ export class MongoDriverError extends MongoError { export class MongoAPIError extends MongoDriverError { /** @internal */ - constructor(message: string) { - super(message); + constructor(message: string, options?: { cause?: Error }) { + super(message, options); } override get name(): string { @@ -714,8 +714,8 @@ export class MongoMissingCredentialsError extends MongoAPIError { */ export class MongoMissingDependencyError extends MongoAPIError { /** @internal */ - constructor(message: string) { - super(message); + constructor(message: string, options: { cause?: Error } = {}) { + super(message, options); } override get name(): string { From 48f7e15678d2b3129ee024f2ba2fa86e11833739 Mon Sep 17 00:00:00 2001 From: Warren James Date: Mon, 7 Aug 2023 16:42:23 -0400 Subject: [PATCH 12/37] fix(NODE-5484): undo unneeded change --- src/error.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/error.ts b/src/error.ts index 2965f79ff38..1d707948607 100644 --- a/src/error.ts +++ b/src/error.ts @@ -732,11 +732,11 @@ export class MongoSystemError extends MongoError { reason?: TopologyDescription; /** @internal */ - constructor(message: string, reason: TopologyDescription, options?: { cause?: Error }) { + constructor(message: string, reason: TopologyDescription) { if (reason && reason.error) { - super(reason.error.message || reason.error, options); + super(reason.error.message || reason.error); } else { - super(message, options); + super(message); } if (reason) { From 661857515bce7af1a88d363d3dd312c31aaed497 Mon Sep 17 00:00:00 2001 From: Warren James Date: Tue, 8 Aug 2023 13:40:59 -0400 Subject: [PATCH 13/37] fix(NODE-5484): override cause field --- src/error.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/error.ts b/src/error.ts index 1d707948607..68d8b74e808 100644 --- a/src/error.ts +++ b/src/error.ts @@ -130,6 +130,7 @@ export class MongoError extends Error { code?: number | string; topologyVersion?: TopologyVersion; connectionGeneration?: number; + override cause?: Error; /** @internal */ constructor(message: string | Error, options?: { cause?: Error }) { From 1d08c4b62353557271d2d5770e78544d0fdf799f Mon Sep 17 00:00:00 2001 From: Warren James Date: Tue, 8 Aug 2023 14:37:05 -0400 Subject: [PATCH 14/37] test(NODE-5484): fix test --- .../client-side-encryption/errors.test.ts | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/test/unit/client-side-encryption/errors.test.ts b/test/unit/client-side-encryption/errors.test.ts index f586be7cad9..2079140492d 100644 --- a/test/unit/client-side-encryption/errors.test.ts +++ b/test/unit/client-side-encryption/errors.test.ts @@ -14,14 +14,20 @@ describe('ClientEncryption', function () { describe('Errors', function () { const errors = [ new MongoCryptAzureKMSRequestError(''), - new MongoCryptCreateDataKeyError({ - encryptedFields: {}, - cause: new Error() - }), - new MongoCryptCreateEncryptedCollectionError({ - encryptedFields: {}, - cause: new Error() - }), + new MongoCryptCreateDataKeyError( + { + encryptedFields: {} + }, + { + cause: new Error() + } + ), + new MongoCryptCreateEncryptedCollectionError( + { + encryptedFields: {} + }, + { cause: new Error() } + ), new MongoCryptError(''), new MongoCryptInvalidArgumentError('') ]; From 2a5833871d417f4d01015e22ee4b88deacefc73e Mon Sep 17 00:00:00 2001 From: Warren James Date: Tue, 8 Aug 2023 15:49:23 -0400 Subject: [PATCH 15/37] test(NODE-5484): update test --- test/integration/node-specific/errors.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/integration/node-specific/errors.test.ts b/test/integration/node-specific/errors.test.ts index 50112970460..2432addf53a 100644 --- a/test/integration/node-specific/errors.test.ts +++ b/test/integration/node-specific/errors.test.ts @@ -18,7 +18,7 @@ describe('Error (Integration)', function () { ]) { it(`constructs the message properly with an array of ${errors.length} errors`, () => { const error = new AggregateError(errors); - const mongoError = new MongoError(error); + const mongoError = new MongoError(message, { cause: error }); expect(mongoError.message).to.equal(message); }); @@ -28,14 +28,14 @@ describe('Error (Integration)', function () { it(`uses the AggregateError's message`, () => { const error = new AggregateError([new Error('non-empty')]); error.message = 'custom error message'; - const mongoError = new MongoError(error); + const mongoError = new MongoError(error, { cause: error }); expect(mongoError.message).to.equal('custom error message'); }); }); it('sets the AggregateError to the cause property', () => { const error = new AggregateError([new Error('error 1')]); - const mongoError = new MongoError(error); + const mongoError = new MongoError(error, { cause: error }); expect(mongoError.cause).to.equal(error); }); }); From 12d8aa7b96faa03177b454564e8e4fb4c7159c97 Mon Sep 17 00:00:00 2001 From: Warren James Date: Tue, 8 Aug 2023 16:29:41 -0400 Subject: [PATCH 16/37] test(NODE-5484): remove duplicate describe block --- .../client-side-encryption/errors.test.ts | 54 +++++++++---------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/test/unit/client-side-encryption/errors.test.ts b/test/unit/client-side-encryption/errors.test.ts index 2079140492d..6eaa0dbd6b5 100644 --- a/test/unit/client-side-encryption/errors.test.ts +++ b/test/unit/client-side-encryption/errors.test.ts @@ -10,34 +10,32 @@ import { } from '../../../src/client-side-encryption/errors'; import { MongoError } from '../../mongodb'; -describe('ClientEncryption', function () { - describe('Errors', function () { - const errors = [ - new MongoCryptAzureKMSRequestError(''), - new MongoCryptCreateDataKeyError( - { - encryptedFields: {} - }, - { - cause: new Error() - } - ), - new MongoCryptCreateEncryptedCollectionError( - { - encryptedFields: {} - }, - { cause: new Error() } - ), - new MongoCryptError(''), - new MongoCryptInvalidArgumentError('') - ]; +describe('MongoCryptError', function () { + const errors = [ + new MongoCryptAzureKMSRequestError(''), + new MongoCryptCreateDataKeyError( + { + encryptedFields: {} + }, + { + cause: new Error() + } + ), + new MongoCryptCreateEncryptedCollectionError( + { + encryptedFields: {} + }, + { cause: new Error() } + ), + new MongoCryptError(''), + new MongoCryptInvalidArgumentError('') + ]; - for (const err of errors) { - describe(err.name, function () { - it('is subclass of MongoError', function () { - expect(err).to.be.instanceOf(MongoError); - }); + for (const err of errors) { + describe(err.name, function () { + it('is subclass of MongoError', function () { + expect(err).to.be.instanceOf(MongoError); }); - } - }); + }); + } }); From 484519dad3490e48b7c2be50d4bac4c93a035368 Mon Sep 17 00:00:00 2001 From: Warren James Date: Tue, 8 Aug 2023 16:52:52 -0400 Subject: [PATCH 17/37] test(NODE-5484): fix unit test --- test/unit/error.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/error.test.ts b/test/unit/error.test.ts index f995a8ff62a..f57aef9b06b 100644 --- a/test/unit/error.test.ts +++ b/test/unit/error.test.ts @@ -99,7 +99,7 @@ describe('MongoErrors', () => { expect(err).to.be.an.instanceof(Error); expect(err.name).to.equal('MongoError'); expect(err.message).to.equal(errorMessage); - expect(err).to.have.property('cause', inputError); + expect(err).to.not.have.property('cause'); }); }); @@ -169,7 +169,7 @@ describe('MongoErrors', () => { context('when options.cause is not set', () => { it('attaches the cause property to the instance', () => { const error = new MongoMissingDependencyError('missing!', { cause: undefined }); - expect(error).to.not.have.property('cause'); + expect(error).to.have.property('cause').that.is.undefined; }); }); }); From d8ee5896ca90928356bb1c69fd1cf2292f6d02bf Mon Sep 17 00:00:00 2001 From: Warren James Date: Thu, 10 Aug 2023 12:00:12 -0400 Subject: [PATCH 18/37] docs(NODE-5484): update MongoError API docs --- src/bulk/common.ts | 10 +- src/client-side-encryption/errors.ts | 50 ++++- src/cmap/errors.ts | 40 +++- src/error.ts | 320 ++++++++++++++++++++++++--- 4 files changed, 378 insertions(+), 42 deletions(-) diff --git a/src/bulk/common.ts b/src/bulk/common.ts index 95005b01f35..05d14634fb4 100644 --- a/src/bulk/common.ts +++ b/src/bulk/common.ts @@ -598,7 +598,15 @@ export class MongoBulkWriteError extends MongoServerError { writeErrors: OneOrMore = []; err?: WriteConcernError; - /** @internal Creates a new MongoBulkWriteError */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor( error: | { message: string; code: number; writeErrors?: WriteError[] } diff --git a/src/client-side-encryption/errors.ts b/src/client-side-encryption/errors.ts index e905b2304a8..7dd9f1e67d9 100644 --- a/src/client-side-encryption/errors.ts +++ b/src/client-side-encryption/errors.ts @@ -6,7 +6,15 @@ import { MongoError } from '../error'; * An error indicating that something went wrong specifically with MongoDB Client Encryption */ export class MongoCryptError extends MongoError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string, options: { cause?: Error } = {}) { super(message, options); } @@ -22,7 +30,15 @@ export class MongoCryptError extends MongoError { * An error indicating an invalid argument was provided to an encryption API. */ export class MongoCryptInvalidArgumentError extends MongoCryptError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string) { super(message); } @@ -37,7 +53,15 @@ export class MongoCryptInvalidArgumentError extends MongoCryptError { */ export class MongoCryptCreateDataKeyError extends MongoCryptError { encryptedFields: Document; - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(encryptedFields: Document, { cause }: { cause: Error }) { super(`Unable to complete creating data keys: ${cause.message}`, { cause }); this.encryptedFields = encryptedFields; @@ -54,7 +78,15 @@ export class MongoCryptCreateDataKeyError extends MongoCryptError { */ export class MongoCryptCreateEncryptedCollectionError extends MongoCryptError { encryptedFields: Document; - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(encryptedFields: Document, { cause }: { cause: Error }) { super(`Unable to create collection: ${cause.message}`, { cause }); this.encryptedFields = encryptedFields; @@ -72,7 +104,15 @@ export class MongoCryptCreateEncryptedCollectionError extends MongoCryptError { export class MongoCryptAzureKMSRequestError extends MongoCryptError { /** The body of the http response that failed, if present. */ body?: Document; - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string, body?: Document) { super(message); this.body = body; diff --git a/src/cmap/errors.ts b/src/cmap/errors.ts index b6916f77665..054c8873b42 100644 --- a/src/cmap/errors.ts +++ b/src/cmap/errors.ts @@ -9,7 +9,15 @@ export class PoolClosedError extends MongoDriverError { /** The address of the connection pool */ address: string; - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(pool: ConnectionPool) { super('Attempted to check out a connection from closed connection pool'); this.address = pool.address; @@ -28,7 +36,15 @@ export class PoolClearedError extends MongoNetworkError { /** The address of the connection pool */ address: string; - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(pool: ConnectionPool, message?: string) { const errorMessage = message ? message @@ -49,7 +65,15 @@ export class PoolClearedError extends MongoNetworkError { * @category Error */ export class PoolClearedOnNetworkError extends PoolClearedError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(pool: ConnectionPool) { super(pool, `Connection to ${pool.address} interrupted due to server monitor timeout`); } @@ -67,7 +91,15 @@ export class WaitQueueTimeoutError extends MongoDriverError { /** The address of the connection pool */ address: string; - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string, address: string) { super(message); this.address = address; diff --git a/src/error.ts b/src/error.ts index 68d8b74e808..335a099d3b0 100644 --- a/src/error.ts +++ b/src/error.ts @@ -132,7 +132,15 @@ export class MongoError extends Error { connectionGeneration?: number; override cause?: Error; - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string | Error, options?: { cause?: Error }) { super(MongoError.buildErrorMessage(message), options); this[kErrorLabels] = new Set(); @@ -193,7 +201,15 @@ export class MongoServerError extends MongoError { ok?: number; [key: string]: any; - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: ErrorDescription) { super(message.message || message.errmsg || message.$err || 'n/a'); if (message.errorLabels) { @@ -218,7 +234,15 @@ export class MongoServerError extends MongoError { * @category Error */ export class MongoDriverError extends MongoError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string, options?: { cause?: Error }) { super(message, options); } @@ -239,7 +263,15 @@ export class MongoDriverError extends MongoError { */ export class MongoAPIError extends MongoDriverError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string, options?: { cause?: Error }) { super(message, options); } @@ -260,7 +292,15 @@ export class MongoAPIError extends MongoDriverError { * @category Error */ export class MongoRuntimeError extends MongoDriverError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string) { super(message); } @@ -278,7 +318,15 @@ export class MongoRuntimeError extends MongoDriverError { * @category Error */ export class MongoBatchReExecutionError extends MongoAPIError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message = 'This batch has already been executed, create new batch to execute') { super(message); } @@ -296,7 +344,15 @@ export class MongoBatchReExecutionError extends MongoAPIError { * @category Error */ export class MongoDecompressionError extends MongoRuntimeError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string) { super(message); } @@ -314,7 +370,15 @@ export class MongoDecompressionError extends MongoRuntimeError { * @category Error */ export class MongoNotConnectedError extends MongoAPIError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string) { super(message); } @@ -332,7 +396,15 @@ export class MongoNotConnectedError extends MongoAPIError { * @category Error */ export class MongoTransactionError extends MongoAPIError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string) { super(message); } @@ -350,7 +422,15 @@ export class MongoTransactionError extends MongoAPIError { * @category Error */ export class MongoExpiredSessionError extends MongoAPIError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message = 'Cannot use a session that has ended') { super(message); } @@ -368,7 +448,15 @@ export class MongoExpiredSessionError extends MongoAPIError { * @category Error */ export class MongoKerberosError extends MongoRuntimeError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string) { super(message); } @@ -386,7 +474,15 @@ export class MongoKerberosError extends MongoRuntimeError { * @category Error */ export class MongoAWSError extends MongoRuntimeError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string) { super(message); } @@ -404,7 +500,15 @@ export class MongoAWSError extends MongoRuntimeError { * @category Error */ export class MongoAzureError extends MongoRuntimeError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string) { super(message); } @@ -421,7 +525,15 @@ export class MongoAzureError extends MongoRuntimeError { * @category Error */ export class MongoChangeStreamError extends MongoRuntimeError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string) { super(message); } @@ -438,7 +550,15 @@ export class MongoChangeStreamError extends MongoRuntimeError { * @category Error */ export class MongoTailableCursorError extends MongoAPIError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message = 'Tailable cursor does not support this operation') { super(message); } @@ -454,7 +574,15 @@ export class MongoTailableCursorError extends MongoAPIError { * @category Error */ export class MongoGridFSStreamError extends MongoRuntimeError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string) { super(message); } @@ -472,7 +600,15 @@ export class MongoGridFSStreamError extends MongoRuntimeError { * @category Error */ export class MongoGridFSChunkError extends MongoRuntimeError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string) { super(message); } @@ -499,7 +635,15 @@ export class MongoGridFSChunkError extends MongoRuntimeError { * @category Error */ export class MongoUnexpectedServerResponseError extends MongoRuntimeError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string) { super(message); } @@ -517,7 +661,15 @@ export class MongoUnexpectedServerResponseError extends MongoRuntimeError { * @category Error */ export class MongoCursorInUseError extends MongoAPIError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message = 'Cursor is already initialized') { super(message); } @@ -535,7 +687,15 @@ export class MongoCursorInUseError extends MongoAPIError { * @category Error */ export class MongoServerClosedError extends MongoAPIError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message = 'Server is closed') { super(message); } @@ -552,7 +712,15 @@ export class MongoServerClosedError extends MongoAPIError { * @category Error */ export class MongoCursorExhaustedError extends MongoAPIError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message?: string) { super(message || 'Cursor is exhausted'); } @@ -570,7 +738,15 @@ export class MongoCursorExhaustedError extends MongoAPIError { * @category Error */ export class MongoTopologyClosedError extends MongoAPIError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message = 'Topology is closed') { super(message); } @@ -601,7 +777,15 @@ export class MongoNetworkError extends MongoError { /** @internal */ [kBeforeHandshake]?: boolean; - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string | Error, options?: MongoNetworkErrorOptions) { super(message); @@ -624,7 +808,15 @@ export class MongoNetworkError extends MongoError { * mongodb-client-encryption has a dependency on this error with an instanceof check */ export class MongoNetworkTimeoutError extends MongoNetworkError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string, options?: MongoNetworkErrorOptions) { super(message, options); } @@ -640,7 +832,15 @@ export class MongoNetworkTimeoutError extends MongoNetworkError { * @category Error */ export class MongoParseError extends MongoDriverError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string) { super(message); } @@ -659,7 +859,15 @@ export class MongoParseError extends MongoDriverError { * @category Error */ export class MongoInvalidArgumentError extends MongoAPIError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string) { super(message); } @@ -678,7 +886,15 @@ export class MongoInvalidArgumentError extends MongoAPIError { * @category Error */ export class MongoCompatibilityError extends MongoAPIError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string) { super(message); } @@ -697,7 +913,15 @@ export class MongoCompatibilityError extends MongoAPIError { * @category Error */ export class MongoMissingCredentialsError extends MongoAPIError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string) { super(message); } @@ -714,7 +938,15 @@ export class MongoMissingCredentialsError extends MongoAPIError { * @category Error */ export class MongoMissingDependencyError extends MongoAPIError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string, options: { cause?: Error } = {}) { super(message, options); } @@ -732,7 +964,15 @@ export class MongoSystemError extends MongoError { /** An optional reason context, such as an error saved during flow of monitoring and selecting servers */ reason?: TopologyDescription; - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string, reason: TopologyDescription) { if (reason && reason.error) { super(reason.error.message || reason.error); @@ -758,7 +998,15 @@ export class MongoSystemError extends MongoError { * @category Error */ export class MongoServerSelectionError extends MongoSystemError { - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: string, reason: TopologyDescription) { super(message, reason); } @@ -790,7 +1038,15 @@ export class MongoWriteConcernError extends MongoServerError { /** The result document (provided if ok: 1) */ result?: Document; - /** @internal */ + /** + * Do not use this constructor. It is meant for internal use only. + * + * @remarks + * This class is only meant to be constructed within the driver. As such this constructor is + * not subject to compatibility guarantees under semantic versioning and may change at any time. + * + * @public + **/ constructor(message: ErrorDescription, result?: Document) { if (result && Array.isArray(result.errorLabels)) { message.errorLabels = result.errorLabels; From 0838e97f0119016311365c27cdac4d65b73b887c Mon Sep 17 00:00:00 2001 From: Warren James Date: Thu, 10 Aug 2023 13:17:31 -0400 Subject: [PATCH 19/37] docs(NODE-5484): Refine docs --- src/bulk/common.ts | 3 +- src/client-side-encryption/errors.ts | 15 +++-- src/cmap/errors.ts | 12 ++-- src/error.ts | 96 ++++++++++++++++++---------- 4 files changed, 84 insertions(+), 42 deletions(-) diff --git a/src/bulk/common.ts b/src/bulk/common.ts index 05d14634fb4..58368f0bd29 100644 --- a/src/bulk/common.ts +++ b/src/bulk/common.ts @@ -599,7 +599,8 @@ export class MongoBulkWriteError extends MongoServerError { err?: WriteConcernError; /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is diff --git a/src/client-side-encryption/errors.ts b/src/client-side-encryption/errors.ts index 7dd9f1e67d9..df7395ce72f 100644 --- a/src/client-side-encryption/errors.ts +++ b/src/client-side-encryption/errors.ts @@ -7,7 +7,8 @@ import { MongoError } from '../error'; */ export class MongoCryptError extends MongoError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -31,7 +32,8 @@ export class MongoCryptError extends MongoError { */ export class MongoCryptInvalidArgumentError extends MongoCryptError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -54,7 +56,8 @@ export class MongoCryptInvalidArgumentError extends MongoCryptError { export class MongoCryptCreateDataKeyError extends MongoCryptError { encryptedFields: Document; /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -79,7 +82,8 @@ export class MongoCryptCreateDataKeyError extends MongoCryptError { export class MongoCryptCreateEncryptedCollectionError extends MongoCryptError { encryptedFields: Document; /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -105,7 +109,8 @@ export class MongoCryptAzureKMSRequestError extends MongoCryptError { /** The body of the http response that failed, if present. */ body?: Document; /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is diff --git a/src/cmap/errors.ts b/src/cmap/errors.ts index 054c8873b42..969107595e0 100644 --- a/src/cmap/errors.ts +++ b/src/cmap/errors.ts @@ -10,7 +10,8 @@ export class PoolClosedError extends MongoDriverError { address: string; /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -37,7 +38,8 @@ export class PoolClearedError extends MongoNetworkError { address: string; /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -66,7 +68,8 @@ export class PoolClearedError extends MongoNetworkError { */ export class PoolClearedOnNetworkError extends PoolClearedError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -92,7 +95,8 @@ export class WaitQueueTimeoutError extends MongoDriverError { address: string; /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is diff --git a/src/error.ts b/src/error.ts index 335a099d3b0..ab76cbbe2d0 100644 --- a/src/error.ts +++ b/src/error.ts @@ -133,7 +133,8 @@ export class MongoError extends Error { override cause?: Error; /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -202,7 +203,8 @@ export class MongoServerError extends MongoError { [key: string]: any; /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -235,7 +237,8 @@ export class MongoServerError extends MongoError { */ export class MongoDriverError extends MongoError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -264,7 +267,8 @@ export class MongoDriverError extends MongoError { export class MongoAPIError extends MongoDriverError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -293,7 +297,8 @@ export class MongoAPIError extends MongoDriverError { */ export class MongoRuntimeError extends MongoDriverError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -319,7 +324,8 @@ export class MongoRuntimeError extends MongoDriverError { */ export class MongoBatchReExecutionError extends MongoAPIError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -345,7 +351,8 @@ export class MongoBatchReExecutionError extends MongoAPIError { */ export class MongoDecompressionError extends MongoRuntimeError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -371,7 +378,8 @@ export class MongoDecompressionError extends MongoRuntimeError { */ export class MongoNotConnectedError extends MongoAPIError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -397,7 +405,8 @@ export class MongoNotConnectedError extends MongoAPIError { */ export class MongoTransactionError extends MongoAPIError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -423,7 +432,8 @@ export class MongoTransactionError extends MongoAPIError { */ export class MongoExpiredSessionError extends MongoAPIError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -449,7 +459,8 @@ export class MongoExpiredSessionError extends MongoAPIError { */ export class MongoKerberosError extends MongoRuntimeError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -475,7 +486,8 @@ export class MongoKerberosError extends MongoRuntimeError { */ export class MongoAWSError extends MongoRuntimeError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -501,7 +513,8 @@ export class MongoAWSError extends MongoRuntimeError { */ export class MongoAzureError extends MongoRuntimeError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -526,7 +539,8 @@ export class MongoAzureError extends MongoRuntimeError { */ export class MongoChangeStreamError extends MongoRuntimeError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -551,7 +565,8 @@ export class MongoChangeStreamError extends MongoRuntimeError { */ export class MongoTailableCursorError extends MongoAPIError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -575,7 +590,8 @@ export class MongoTailableCursorError extends MongoAPIError { */ export class MongoGridFSStreamError extends MongoRuntimeError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -601,7 +617,8 @@ export class MongoGridFSStreamError extends MongoRuntimeError { */ export class MongoGridFSChunkError extends MongoRuntimeError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -636,7 +653,8 @@ export class MongoGridFSChunkError extends MongoRuntimeError { */ export class MongoUnexpectedServerResponseError extends MongoRuntimeError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -662,7 +680,8 @@ export class MongoUnexpectedServerResponseError extends MongoRuntimeError { */ export class MongoCursorInUseError extends MongoAPIError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -688,7 +707,8 @@ export class MongoCursorInUseError extends MongoAPIError { */ export class MongoServerClosedError extends MongoAPIError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -713,7 +733,8 @@ export class MongoServerClosedError extends MongoAPIError { */ export class MongoCursorExhaustedError extends MongoAPIError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -739,7 +760,8 @@ export class MongoCursorExhaustedError extends MongoAPIError { */ export class MongoTopologyClosedError extends MongoAPIError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -778,7 +800,8 @@ export class MongoNetworkError extends MongoError { [kBeforeHandshake]?: boolean; /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -809,7 +832,8 @@ export class MongoNetworkError extends MongoError { */ export class MongoNetworkTimeoutError extends MongoNetworkError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -833,7 +857,8 @@ export class MongoNetworkTimeoutError extends MongoNetworkError { */ export class MongoParseError extends MongoDriverError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -860,7 +885,8 @@ export class MongoParseError extends MongoDriverError { */ export class MongoInvalidArgumentError extends MongoAPIError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -887,7 +913,8 @@ export class MongoInvalidArgumentError extends MongoAPIError { */ export class MongoCompatibilityError extends MongoAPIError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -914,7 +941,8 @@ export class MongoCompatibilityError extends MongoAPIError { */ export class MongoMissingCredentialsError extends MongoAPIError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -939,7 +967,8 @@ export class MongoMissingCredentialsError extends MongoAPIError { */ export class MongoMissingDependencyError extends MongoAPIError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -965,7 +994,8 @@ export class MongoSystemError extends MongoError { reason?: TopologyDescription; /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -999,7 +1029,8 @@ export class MongoSystemError extends MongoError { */ export class MongoServerSelectionError extends MongoSystemError { /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is @@ -1039,7 +1070,8 @@ export class MongoWriteConcernError extends MongoServerError { result?: Document; /** - * Do not use this constructor. It is meant for internal use only. + * **Do not use this constructor!** + * Meant for internal use only. * * @remarks * This class is only meant to be constructed within the driver. As such this constructor is From 7120ef733f8f738002e407e5808aa8165dbd4f64 Mon Sep 17 00:00:00 2001 From: Warren James Date: Thu, 10 Aug 2023 13:39:25 -0400 Subject: [PATCH 20/37] docs(NODE-5484): formatting and wording --- src/bulk/common.ts | 5 +- src/client-side-encryption/errors.ts | 25 +++-- src/cmap/errors.ts | 20 ++-- src/error.ts | 160 ++++++++++++++++----------- 4 files changed, 126 insertions(+), 84 deletions(-) diff --git a/src/bulk/common.ts b/src/bulk/common.ts index 58368f0bd29..5bc149122f7 100644 --- a/src/bulk/common.ts +++ b/src/bulk/common.ts @@ -600,11 +600,12 @@ export class MongoBulkWriteError extends MongoServerError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ diff --git a/src/client-side-encryption/errors.ts b/src/client-side-encryption/errors.ts index df7395ce72f..f8d3edac139 100644 --- a/src/client-side-encryption/errors.ts +++ b/src/client-side-encryption/errors.ts @@ -8,11 +8,12 @@ import { MongoError } from '../error'; export class MongoCryptError extends MongoError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -33,11 +34,12 @@ export class MongoCryptError extends MongoError { export class MongoCryptInvalidArgumentError extends MongoCryptError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -57,11 +59,12 @@ export class MongoCryptCreateDataKeyError extends MongoCryptError { encryptedFields: Document; /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -83,11 +86,12 @@ export class MongoCryptCreateEncryptedCollectionError extends MongoCryptError { encryptedFields: Document; /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -110,11 +114,12 @@ export class MongoCryptAzureKMSRequestError extends MongoCryptError { body?: Document; /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ diff --git a/src/cmap/errors.ts b/src/cmap/errors.ts index 969107595e0..0841fd7b02a 100644 --- a/src/cmap/errors.ts +++ b/src/cmap/errors.ts @@ -11,11 +11,12 @@ export class PoolClosedError extends MongoDriverError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -39,11 +40,12 @@ export class PoolClearedError extends MongoNetworkError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -69,11 +71,12 @@ export class PoolClearedError extends MongoNetworkError { export class PoolClearedOnNetworkError extends PoolClearedError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -96,11 +99,12 @@ export class WaitQueueTimeoutError extends MongoDriverError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ diff --git a/src/error.ts b/src/error.ts index ab76cbbe2d0..1fcb421b075 100644 --- a/src/error.ts +++ b/src/error.ts @@ -134,11 +134,12 @@ export class MongoError extends Error { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -204,11 +205,12 @@ export class MongoServerError extends MongoError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -238,11 +240,12 @@ export class MongoServerError extends MongoError { export class MongoDriverError extends MongoError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -268,11 +271,12 @@ export class MongoDriverError extends MongoError { export class MongoAPIError extends MongoDriverError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -298,11 +302,12 @@ export class MongoAPIError extends MongoDriverError { export class MongoRuntimeError extends MongoDriverError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -325,11 +330,12 @@ export class MongoRuntimeError extends MongoDriverError { export class MongoBatchReExecutionError extends MongoAPIError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -352,11 +358,12 @@ export class MongoBatchReExecutionError extends MongoAPIError { export class MongoDecompressionError extends MongoRuntimeError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -379,11 +386,12 @@ export class MongoDecompressionError extends MongoRuntimeError { export class MongoNotConnectedError extends MongoAPIError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -406,11 +414,12 @@ export class MongoNotConnectedError extends MongoAPIError { export class MongoTransactionError extends MongoAPIError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -433,11 +442,12 @@ export class MongoTransactionError extends MongoAPIError { export class MongoExpiredSessionError extends MongoAPIError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -460,11 +470,12 @@ export class MongoExpiredSessionError extends MongoAPIError { export class MongoKerberosError extends MongoRuntimeError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -487,11 +498,12 @@ export class MongoKerberosError extends MongoRuntimeError { export class MongoAWSError extends MongoRuntimeError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -514,11 +526,12 @@ export class MongoAWSError extends MongoRuntimeError { export class MongoAzureError extends MongoRuntimeError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -540,11 +553,12 @@ export class MongoAzureError extends MongoRuntimeError { export class MongoChangeStreamError extends MongoRuntimeError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -566,11 +580,12 @@ export class MongoChangeStreamError extends MongoRuntimeError { export class MongoTailableCursorError extends MongoAPIError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -591,11 +606,12 @@ export class MongoTailableCursorError extends MongoAPIError { export class MongoGridFSStreamError extends MongoRuntimeError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -618,11 +634,12 @@ export class MongoGridFSStreamError extends MongoRuntimeError { export class MongoGridFSChunkError extends MongoRuntimeError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -654,11 +671,12 @@ export class MongoGridFSChunkError extends MongoRuntimeError { export class MongoUnexpectedServerResponseError extends MongoRuntimeError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -681,11 +699,12 @@ export class MongoUnexpectedServerResponseError extends MongoRuntimeError { export class MongoCursorInUseError extends MongoAPIError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -708,11 +727,12 @@ export class MongoCursorInUseError extends MongoAPIError { export class MongoServerClosedError extends MongoAPIError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -734,11 +754,12 @@ export class MongoServerClosedError extends MongoAPIError { export class MongoCursorExhaustedError extends MongoAPIError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -761,11 +782,12 @@ export class MongoCursorExhaustedError extends MongoAPIError { export class MongoTopologyClosedError extends MongoAPIError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -801,11 +823,12 @@ export class MongoNetworkError extends MongoError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -833,11 +856,12 @@ export class MongoNetworkError extends MongoError { export class MongoNetworkTimeoutError extends MongoNetworkError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -858,11 +882,12 @@ export class MongoNetworkTimeoutError extends MongoNetworkError { export class MongoParseError extends MongoDriverError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -886,11 +911,12 @@ export class MongoParseError extends MongoDriverError { export class MongoInvalidArgumentError extends MongoAPIError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -914,11 +940,12 @@ export class MongoInvalidArgumentError extends MongoAPIError { export class MongoCompatibilityError extends MongoAPIError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -942,11 +969,12 @@ export class MongoCompatibilityError extends MongoAPIError { export class MongoMissingCredentialsError extends MongoAPIError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -968,11 +996,12 @@ export class MongoMissingCredentialsError extends MongoAPIError { export class MongoMissingDependencyError extends MongoAPIError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -995,11 +1024,12 @@ export class MongoSystemError extends MongoError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -1030,11 +1060,12 @@ export class MongoSystemError extends MongoError { export class MongoServerSelectionError extends MongoSystemError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ @@ -1071,11 +1102,12 @@ export class MongoWriteConcernError extends MongoServerError { /** * **Do not use this constructor!** + * * Meant for internal use only. * * @remarks - * This class is only meant to be constructed within the driver. As such this constructor is - * not subject to compatibility guarantees under semantic versioning and may change at any time. + * This class is only meant to be constructed within the driver. This constructor is + * not subject to semantic versioning compatiblity guarantees and may change at any time. * * @public **/ From 414d53adaf2971d63e412be16ffb29e154039ffc Mon Sep 17 00:00:00 2001 From: Warren James Date: Tue, 15 Aug 2023 15:09:43 -0400 Subject: [PATCH 21/37] Update etc/notes/errors.md Co-authored-by: Bailey Pearson --- etc/notes/errors.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/etc/notes/errors.md b/etc/notes/errors.md index 4dac07b5261..95dd6011086 100644 --- a/etc/notes/errors.md +++ b/etc/notes/errors.md @@ -147,9 +147,9 @@ These are errors thrown from the `mongodb-client-encryption` bindings - #### MongoCryptInvalidCreateEncryptedCollectionError - Thrown when `ClientEncryption.createEncryptedCollection()` failed to create a collection - #### MongoCryptInvalidCreateAzureKMSRequestError - - Thrown when `mongodb-client-encryption` failed to auto-refresh Azure KMS credentials + - Thrown when auto-fetching KMS credentials fails to auto-refresh Azure KMS credentials - #### MongoCryptKMSRequestNetworkTimeoutError - - Thrown when `mongodb-client-encryption` times out when fetching KMS credentials + - Thrown when auto-fetching KMS credentials times out ## Test Plan From b51ad7958b53e733b02cd30edf088f033c9636d7 Mon Sep 17 00:00:00 2001 From: Warren James Date: Tue, 15 Aug 2023 15:37:30 -0400 Subject: [PATCH 22/37] docs(NODE-5484): update docs --- etc/notes/errors.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/notes/errors.md b/etc/notes/errors.md index 95dd6011086..c3407a214e6 100644 --- a/etc/notes/errors.md +++ b/etc/notes/errors.md @@ -138,7 +138,7 @@ These are errors which originate from faulty environment setup. ### `MongoCryptError` -These are errors thrown from the `mongodb-client-encryption` bindings +These are errors thrown from the driver's client side encryption logic. - #### MongoCryptInvalidArgumentError - Thrown when an invalid argument has been provided to an encryption API From 161d32b1144ead074920dbdec99165c116c9a976 Mon Sep 17 00:00:00 2001 From: Warren James Date: Wed, 16 Aug 2023 09:45:45 -0400 Subject: [PATCH 23/37] Update etc/notes/errors.md Co-authored-by: Bailey Pearson --- etc/notes/errors.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/etc/notes/errors.md b/etc/notes/errors.md index c3407a214e6..a0b831a2048 100644 --- a/etc/notes/errors.md +++ b/etc/notes/errors.md @@ -147,9 +147,9 @@ These are errors thrown from the driver's client side encryption logic. - #### MongoCryptInvalidCreateEncryptedCollectionError - Thrown when `ClientEncryption.createEncryptedCollection()` failed to create a collection - #### MongoCryptInvalidCreateAzureKMSRequestError - - Thrown when auto-fetching KMS credentials fails to auto-refresh Azure KMS credentials + - Thrown when the driver encounters an error when fetching Azure KMS credentials - #### MongoCryptKMSRequestNetworkTimeoutError - - Thrown when auto-fetching KMS credentials times out + - Thrown when the HTTP request to the IDMS server times out when fetching Azure KMS credentials ## Test Plan From 564d1173a084b2f1dd08e4b97a7edd0d1f5b3519 Mon Sep 17 00:00:00 2001 From: Warren James Date: Wed, 16 Aug 2023 10:05:11 -0400 Subject: [PATCH 24/37] docs(NODE-5484): update wording --- etc/notes/errors.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/etc/notes/errors.md b/etc/notes/errors.md index a0b831a2048..d0f8e6b6e95 100644 --- a/etc/notes/errors.md +++ b/etc/notes/errors.md @@ -143,9 +143,9 @@ These are errors thrown from the driver's client side encryption logic. - #### MongoCryptInvalidArgumentError - Thrown when an invalid argument has been provided to an encryption API - #### MongoCryptInvalidCreateDataKeyError - - Thrown when `ClientEncryption.createEncryptedCollection()` failed to create data keys + - Thrown when the driver fails to create data keys for an encrypted collection - #### MongoCryptInvalidCreateEncryptedCollectionError - - Thrown when `ClientEncryption.createEncryptedCollection()` failed to create a collection + - Thrown when the driver fails to create an encrypted collection - #### MongoCryptInvalidCreateAzureKMSRequestError - Thrown when the driver encounters an error when fetching Azure KMS credentials - #### MongoCryptKMSRequestNetworkTimeoutError From aaa2ebec28f5be2b19014a1020eaee4505e97332 Mon Sep 17 00:00:00 2001 From: Warren James Date: Wed, 16 Aug 2023 15:04:38 -0400 Subject: [PATCH 25/37] fix(NODE-5484): update constructors to not take error --- src/bulk/common.ts | 2 +- src/client-side-encryption/errors.ts | 10 ++-- src/cmap/connect.ts | 2 +- src/cmap/errors.ts | 8 +-- src/error.ts | 75 ++++++++++++++-------------- src/sdam/monitor.ts | 2 +- 6 files changed, 50 insertions(+), 49 deletions(-) diff --git a/src/bulk/common.ts b/src/bulk/common.ts index 5bc149122f7..054a2e9e3bc 100644 --- a/src/bulk/common.ts +++ b/src/bulk/common.ts @@ -605,7 +605,7 @@ export class MongoBulkWriteError extends MongoServerError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ diff --git a/src/client-side-encryption/errors.ts b/src/client-side-encryption/errors.ts index f8d3edac139..7ab70748a84 100644 --- a/src/client-side-encryption/errors.ts +++ b/src/client-side-encryption/errors.ts @@ -13,7 +13,7 @@ export class MongoCryptError extends MongoError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -39,7 +39,7 @@ export class MongoCryptInvalidArgumentError extends MongoCryptError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -64,7 +64,7 @@ export class MongoCryptCreateDataKeyError extends MongoCryptError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -91,7 +91,7 @@ export class MongoCryptCreateEncryptedCollectionError extends MongoCryptError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -119,7 +119,7 @@ export class MongoCryptAzureKMSRequestError extends MongoCryptError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ diff --git a/src/cmap/connect.ts b/src/cmap/connect.ts index 0ea49e939cd..42cbbdea4e4 100644 --- a/src/cmap/connect.ts +++ b/src/cmap/connect.ts @@ -502,7 +502,7 @@ function makeSocks5Connection(options: MakeConnectionOptions, callback: Callback function connectionFailureError(type: ErrorHandlerEventName, err: Error) { switch (type) { case 'error': - return new MongoNetworkError(err); + return new MongoNetworkError('error', { cause: err }); case 'timeout': return new MongoNetworkTimeoutError('connection timed out'); case 'close': diff --git a/src/cmap/errors.ts b/src/cmap/errors.ts index 0841fd7b02a..1b464bc3e4d 100644 --- a/src/cmap/errors.ts +++ b/src/cmap/errors.ts @@ -16,7 +16,7 @@ export class PoolClosedError extends MongoDriverError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -45,7 +45,7 @@ export class PoolClearedError extends MongoNetworkError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -76,7 +76,7 @@ export class PoolClearedOnNetworkError extends PoolClearedError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -104,7 +104,7 @@ export class WaitQueueTimeoutError extends MongoDriverError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ diff --git a/src/error.ts b/src/error.ts index 1fcb421b075..4f8975dbe12 100644 --- a/src/error.ts +++ b/src/error.ts @@ -139,11 +139,11 @@ export class MongoError extends Error { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ - constructor(message: string | Error, options?: { cause?: Error }) { + constructor(message: string, options?: { cause?: Error }) { super(MongoError.buildErrorMessage(message), options); this[kErrorLabels] = new Set(); } @@ -210,7 +210,7 @@ export class MongoServerError extends MongoError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -245,7 +245,7 @@ export class MongoDriverError extends MongoError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -276,7 +276,7 @@ export class MongoAPIError extends MongoDriverError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -307,7 +307,7 @@ export class MongoRuntimeError extends MongoDriverError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -335,7 +335,7 @@ export class MongoBatchReExecutionError extends MongoAPIError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -363,7 +363,7 @@ export class MongoDecompressionError extends MongoRuntimeError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -391,7 +391,7 @@ export class MongoNotConnectedError extends MongoAPIError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -419,7 +419,7 @@ export class MongoTransactionError extends MongoAPIError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -447,7 +447,7 @@ export class MongoExpiredSessionError extends MongoAPIError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -475,7 +475,7 @@ export class MongoKerberosError extends MongoRuntimeError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -503,7 +503,7 @@ export class MongoAWSError extends MongoRuntimeError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -531,7 +531,7 @@ export class MongoAzureError extends MongoRuntimeError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -558,7 +558,7 @@ export class MongoChangeStreamError extends MongoRuntimeError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -585,7 +585,7 @@ export class MongoTailableCursorError extends MongoAPIError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -611,7 +611,7 @@ export class MongoGridFSStreamError extends MongoRuntimeError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -639,7 +639,7 @@ export class MongoGridFSChunkError extends MongoRuntimeError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -676,7 +676,7 @@ export class MongoUnexpectedServerResponseError extends MongoRuntimeError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -704,7 +704,7 @@ export class MongoCursorInUseError extends MongoAPIError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -732,7 +732,7 @@ export class MongoServerClosedError extends MongoAPIError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -759,7 +759,7 @@ export class MongoCursorExhaustedError extends MongoAPIError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -787,7 +787,7 @@ export class MongoTopologyClosedError extends MongoAPIError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -809,7 +809,8 @@ export function isNetworkErrorBeforeHandshake(err: MongoNetworkError): boolean { /** @public */ export interface MongoNetworkErrorOptions { /** Indicates the timeout happened before a connection handshake completed */ - beforeHandshake: boolean; + beforeHandshake?: boolean; + cause?: Error; } /** @@ -828,12 +829,12 @@ export class MongoNetworkError extends MongoError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ - constructor(message: string | Error, options?: MongoNetworkErrorOptions) { - super(message); + constructor(message: string, options?: MongoNetworkErrorOptions) { + super(message, { cause: options?.cause }); if (options && typeof options.beforeHandshake === 'boolean') { this[kBeforeHandshake] = options.beforeHandshake; @@ -861,7 +862,7 @@ export class MongoNetworkTimeoutError extends MongoNetworkError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -887,7 +888,7 @@ export class MongoParseError extends MongoDriverError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -916,7 +917,7 @@ export class MongoInvalidArgumentError extends MongoAPIError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -945,7 +946,7 @@ export class MongoCompatibilityError extends MongoAPIError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -974,7 +975,7 @@ export class MongoMissingCredentialsError extends MongoAPIError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -1001,7 +1002,7 @@ export class MongoMissingDependencyError extends MongoAPIError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -1029,13 +1030,13 @@ export class MongoSystemError extends MongoError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ constructor(message: string, reason: TopologyDescription) { if (reason && reason.error) { - super(reason.error.message || reason.error); + super(message, { cause: reason.error }); } else { super(message); } @@ -1065,7 +1066,7 @@ export class MongoServerSelectionError extends MongoSystemError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ @@ -1107,7 +1108,7 @@ export class MongoWriteConcernError extends MongoServerError { * * @remarks * This class is only meant to be constructed within the driver. This constructor is - * not subject to semantic versioning compatiblity guarantees and may change at any time. + * not subject to semantic versioning compatibility guarantees and may change at any time. * * @public **/ diff --git a/src/sdam/monitor.ts b/src/sdam/monitor.ts index eec2c30ed7e..8329f28a016 100644 --- a/src/sdam/monitor.ts +++ b/src/sdam/monitor.ts @@ -220,7 +220,7 @@ function checkServer(monitor: Monitor, callback: Callback) { new ServerHeartbeatFailedEvent(monitor.address, calculateDurationInMs(start), err) ); - const error = !(err instanceof MongoError) ? new MongoError(err) : err; + const error = !(err instanceof MongoError) ? new MongoError(err.message, { cause: err }) : err; error.addErrorLabel(MongoErrorLabel.ResetPool); if (error instanceof MongoNetworkTimeoutError) { error.addErrorLabel(MongoErrorLabel.InterruptInUseConnections); From 4ca5acd1b61895911579b511fec09b149ac89604 Mon Sep 17 00:00:00 2001 From: Warren James Date: Wed, 16 Aug 2023 16:11:02 -0400 Subject: [PATCH 26/37] test(NODE-5484): fix test assertions --- .../mongodb-handshake/mongodb-handshake.test.ts | 2 +- test/unit/assorted/wire_version.test.js | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/test/integration/mongodb-handshake/mongodb-handshake.test.ts b/test/integration/mongodb-handshake/mongodb-handshake.test.ts index 2e00d0e2e96..7773d97c5e8 100644 --- a/test/integration/mongodb-handshake/mongodb-handshake.test.ts +++ b/test/integration/mongodb-handshake/mongodb-handshake.test.ts @@ -42,7 +42,7 @@ describe('MongoDB Handshake', () => { } else { expect(error).to.be.instanceOf(MongoServerSelectionError); } - expect(error).to.match(/client metadata document must be less/); + expect(error.cause).to.match(/client metadata document must be less/); }); }); diff --git a/test/unit/assorted/wire_version.test.js b/test/unit/assorted/wire_version.test.js index 7607ff09b7c..468d7a6a5f6 100644 --- a/test/unit/assorted/wire_version.test.js +++ b/test/unit/assorted/wire_version.test.js @@ -2,7 +2,11 @@ const mock = require('../../tools/mongodb-mock/index'); const { expect } = require('chai'); -const { MongoServerSelectionError, MongoClient } = require('../../mongodb'); +const { + MongoServerSelectionError, + MongoCompatibilityError, + MongoClient +} = require('../../mongodb'); const { isHello } = require('../../mongodb'); const minCompatErrMsg = `minimum wire version ${ @@ -49,7 +53,8 @@ describe('Wire Protocol Version', () => { expect.fail('should fail to select server!'); } catch (error) { expect(error).to.be.instanceOf(MongoServerSelectionError); - expect(error).to.have.property('message').that.includes(minCompatErrMsg); + expect(error.cause).to.be.instanceOf(MongoCompatibilityError); + expect(error.cause).to.have.property('message').that.includes(minCompatErrMsg); } }); }); @@ -67,7 +72,8 @@ describe('Wire Protocol Version', () => { expect.fail('should fail to select server!'); } catch (error) { expect(error).to.be.instanceOf(MongoServerSelectionError); - expect(error).to.have.property('message').that.includes(maxCompatErrMsg); + expect(error.cause).to.be.instanceOf(MongoCompatibilityError); + expect(error.cause).to.have.property('message').that.includes(maxCompatErrMsg); } }); }); From 6511534aa8b272095f1e687f99212e2cb5720423 Mon Sep 17 00:00:00 2001 From: Warren James Date: Wed, 16 Aug 2023 16:14:14 -0400 Subject: [PATCH 27/37] test(NODE-5484): start fixing csfle tests --- .../client_side_encryption.prose.test.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/integration/client-side-encryption/client_side_encryption.prose.test.js b/test/integration/client-side-encryption/client_side_encryption.prose.test.js index 2b1bf98a193..26b0ade3579 100644 --- a/test/integration/client-side-encryption/client_side_encryption.prose.test.js +++ b/test/integration/client-side-encryption/client_side_encryption.prose.test.js @@ -1171,9 +1171,8 @@ describe('Client Side Encryption Prose Tests', metadata, function () { .insertOne({ encrypted: 'test' }) .catch(e => e); - expect(insertError) - .to.be.instanceOf(Error) - .to.have.property('name', 'MongoServerSelectionError'); + expect(insertError).to.be.instanceOf(Error); + expect(insertError).to.have.property('cause').that.is.instanceOf(MongoServerSelectionError); // TODO(NODE-5296): check error.message once AggregateErrors are handled correctly expect(insertError, 'Error must contain ECONNREFUSED').to.satisfy( From 65c77673664a04640d44df5d137842cc1b127e01 Mon Sep 17 00:00:00 2001 From: Warren James Date: Fri, 18 Aug 2023 16:30:54 -0400 Subject: [PATCH 28/37] fix(NODE-5484): Update error constructor calls and csfle prose tests --- src/client-side-encryption/auto_encrypter.ts | 3 +- src/cmap/connect.ts | 2 +- src/cmap/errors.ts | 2 +- src/error.ts | 6 ++-- src/sdam/monitor.ts | 4 ++- .../client_side_encryption.prose.test.js | 33 ++++++++++--------- 6 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/client-side-encryption/auto_encrypter.ts b/src/client-side-encryption/auto_encrypter.ts index 6de294b63ab..d6eb0826c8e 100644 --- a/src/client-side-encryption/auto_encrypter.ts +++ b/src/client-side-encryption/auto_encrypter.ts @@ -422,7 +422,8 @@ export class AutoEncrypter { ) { callback( new MongoRuntimeError( - 'Unable to connect to `mongocryptd`, please make sure it is running or in your PATH for auto-spawn' + 'Unable to connect to `mongocryptd`, please make sure it is running or in your PATH for auto-spawn', + { cause: err } ) ); return; diff --git a/src/cmap/connect.ts b/src/cmap/connect.ts index 42cbbdea4e4..3cf6db74474 100644 --- a/src/cmap/connect.ts +++ b/src/cmap/connect.ts @@ -502,7 +502,7 @@ function makeSocks5Connection(options: MakeConnectionOptions, callback: Callback function connectionFailureError(type: ErrorHandlerEventName, err: Error) { switch (type) { case 'error': - return new MongoNetworkError('error', { cause: err }); + return new MongoNetworkError(MongoError.buildErrorMessage(err), { cause: err }); case 'timeout': return new MongoNetworkTimeoutError('connection timed out'); case 'close': diff --git a/src/cmap/errors.ts b/src/cmap/errors.ts index 1b464bc3e4d..af550508e83 100644 --- a/src/cmap/errors.ts +++ b/src/cmap/errors.ts @@ -53,7 +53,7 @@ export class PoolClearedError extends MongoNetworkError { const errorMessage = message ? message : `Connection pool for ${pool.address} was cleared because another operation failed with: "${pool.serverError?.message}"`; - super(errorMessage); + super(errorMessage, pool.serverError ? { cause: pool.serverError } : undefined); this.address = pool.address; this.addErrorLabel(MongoErrorLabel.RetryableWriteError); diff --git a/src/error.ts b/src/error.ts index 4f8975dbe12..bbeafc3b9a9 100644 --- a/src/error.ts +++ b/src/error.ts @@ -149,7 +149,7 @@ export class MongoError extends Error { } /** @internal */ - private static buildErrorMessage(e: Error | string): string { + static buildErrorMessage(e: Error | string): string { if (typeof e === 'string') { return e; } @@ -311,8 +311,8 @@ export class MongoRuntimeError extends MongoDriverError { * * @public **/ - constructor(message: string) { - super(message); + constructor(message: string, options?: { cause?: Error }) { + super(message, options); } override get name(): string { diff --git a/src/sdam/monitor.ts b/src/sdam/monitor.ts index 8329f28a016..bd5702b4af4 100644 --- a/src/sdam/monitor.ts +++ b/src/sdam/monitor.ts @@ -220,7 +220,9 @@ function checkServer(monitor: Monitor, callback: Callback) { new ServerHeartbeatFailedEvent(monitor.address, calculateDurationInMs(start), err) ); - const error = !(err instanceof MongoError) ? new MongoError(err.message, { cause: err }) : err; + const error = !(err instanceof MongoError) + ? new MongoError(MongoError.buildErrorMessage(err), { cause: err }) + : err; error.addErrorLabel(MongoErrorLabel.ResetPool); if (error instanceof MongoNetworkTimeoutError) { error.addErrorLabel(MongoErrorLabel.InterruptInUseConnections); diff --git a/test/integration/client-side-encryption/client_side_encryption.prose.test.js b/test/integration/client-side-encryption/client_side_encryption.prose.test.js index 26b0ade3579..275b4eb1164 100644 --- a/test/integration/client-side-encryption/client_side_encryption.prose.test.js +++ b/test/integration/client-side-encryption/client_side_encryption.prose.test.js @@ -8,7 +8,12 @@ const { dropCollection, APMEventCollector } = require('../shared'); const { EJSON } = BSON; const { LEGACY_HELLO_COMMAND } = require('../../mongodb'); -const { MongoServerError, MongoServerSelectionError, MongoClient } = require('../../mongodb'); +const { + MongoServerError, + MongoServerSelectionError, + MongoClient, + MongoRuntimeError +} = require('../../mongodb'); const { getEncryptExtraOptions } = require('../../tools/utils'); const { installNodeDNSWorkaroundHooks } = require('../../tools/runner/hooks/configuration'); const { coerce, gte } = require('semver'); @@ -1171,17 +1176,17 @@ describe('Client Side Encryption Prose Tests', metadata, function () { .insertOne({ encrypted: 'test' }) .catch(e => e); - expect(insertError).to.be.instanceOf(Error); + expect(insertError).to.be.instanceOf(MongoRuntimeError); expect(insertError).to.have.property('cause').that.is.instanceOf(MongoServerSelectionError); // TODO(NODE-5296): check error.message once AggregateErrors are handled correctly - expect(insertError, 'Error must contain ECONNREFUSED').to.satisfy( + expect(insertError.cause, 'Error must contain ECONNREFUSED').to.satisfy( error => - /ECONNREFUSED/.test(error.message) || + /ECONNREFUSED/.test(error?.cause.message) || !!error.cause?.cause?.errors?.every(e => e.code === 'ECONNREFUSED') ); - expect(insertError).to.be.instanceOf(MongoServerSelectionError); + //expect(insertError.cause).to.be.instanceOf(MongoServerSelectionError); }); }); @@ -1263,16 +1268,14 @@ describe('Client Side Encryption Prose Tests', metadata, function () { const error = await client.connect().catch(e => e); // TODO(NODE-5296): check error.message once AggregateErrors are handled correctly - expect( - error, - 'Error MUST be a MongoServerSelectionError error that contains ECONNREFUSED information' - ) - .to.be.instanceOf(MongoServerSelectionError) - .that.satisfies( - error => - /ECONNREFUSED/.test(error.message) || - !!error.cause?.cause?.errors?.every(e => e.code === 'ECONNREFUSED') - ); + expect(error, 'Error MUST be a MongoServerSelectionError error').to.be.instanceOf( + MongoServerSelectionError + ); + expect(error, 'Error MUST contain ECONNREFUSED information').to.satisfy( + error => + /ECONNREFUSED/.test(error.cause.message) || + !!error.cause?.cause?.errors?.every(e => e.code === 'ECONNREFUSED') + ); }); }); From 4ec65c22008ecc27318bdb7d5dcefd3ac6fe0d74 Mon Sep 17 00:00:00 2001 From: Warren James Date: Mon, 21 Aug 2023 11:15:30 -0400 Subject: [PATCH 29/37] test(NODE-5484): update assertion --- test/integration/mongodb-handshake/mongodb-handshake.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/integration/mongodb-handshake/mongodb-handshake.test.ts b/test/integration/mongodb-handshake/mongodb-handshake.test.ts index 7773d97c5e8..ef39d9f3ff9 100644 --- a/test/integration/mongodb-handshake/mongodb-handshake.test.ts +++ b/test/integration/mongodb-handshake/mongodb-handshake.test.ts @@ -37,12 +37,13 @@ describe('MongoDB Handshake', () => { it('should fail with an error relating to size', async function () { client = this.configuration.newClient({ serverSelectionTimeoutMS: 2000 }); const error = await client.connect().catch(error => error); + console.log(error); if (this.configuration.isLoadBalanced) { expect(error).to.be.instanceOf(MongoServerError); } else { expect(error).to.be.instanceOf(MongoServerSelectionError); } - expect(error.cause).to.match(/client metadata document must be less/); + expect(error.cause ?? error).to.match(/client metadata document must be less/); }); }); From 56920da32bb7c82a67ad0e6195efe496e8319687 Mon Sep 17 00:00:00 2001 From: Warren James Date: Mon, 21 Aug 2023 12:55:13 -0400 Subject: [PATCH 30/37] test(NODE-5484): Fix test assertions --- .../mongodb-handshake/mongodb-handshake.test.ts | 1 - test/manual/socks5.test.ts | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/test/integration/mongodb-handshake/mongodb-handshake.test.ts b/test/integration/mongodb-handshake/mongodb-handshake.test.ts index ef39d9f3ff9..def000a8d38 100644 --- a/test/integration/mongodb-handshake/mongodb-handshake.test.ts +++ b/test/integration/mongodb-handshake/mongodb-handshake.test.ts @@ -37,7 +37,6 @@ describe('MongoDB Handshake', () => { it('should fail with an error relating to size', async function () { client = this.configuration.newClient({ serverSelectionTimeoutMS: 2000 }); const error = await client.connect().catch(error => error); - console.log(error); if (this.configuration.isLoadBalanced) { expect(error).to.be.instanceOf(MongoServerError); } else { diff --git a/test/manual/socks5.test.ts b/test/manual/socks5.test.ts index a37907aff69..1d4fe96aa3b 100644 --- a/test/manual/socks5.test.ts +++ b/test/manual/socks5.test.ts @@ -53,7 +53,7 @@ describe('Socks5 Connectivity', function () { await testConnection(cs.toString(), {}); } catch (err) { expect(err.name).to.equal('MongoServerSelectionError'); - expect(err.message).to.match(/Received invalid Socks5 initial handshake/); + expect(err.cause.message).to.match(/Received invalid Socks5 initial handshake/); return; } expect.fail('missed exception'); @@ -68,7 +68,7 @@ describe('Socks5 Connectivity', function () { }); } catch (err) { expect(err.name).to.equal('MongoServerSelectionError'); - expect(err.message).to.match(/Received invalid Socks5 initial handshake/); + expect(err.cause.message).to.match(/Received invalid Socks5 initial handshake/); return; } expect.fail('missed exception'); @@ -82,7 +82,7 @@ describe('Socks5 Connectivity', function () { await testConnection(cs.toString(), {}); } catch (err) { expect(err.name).to.equal('MongoServerSelectionError'); - expect(err.message).to.match(/Received invalid Socks5 initial handshake/); + expect(err.cause.message).to.match(/Received invalid Socks5 initial handshake/); return; } expect.fail('missed exception'); @@ -96,7 +96,7 @@ describe('Socks5 Connectivity', function () { }); } catch (err) { expect(err.name).to.equal('MongoServerSelectionError'); - expect(err.message).to.match(/Received invalid Socks5 initial handshake/); + expect(err.cause.message).to.match(/Received invalid Socks5 initial handshake/); return; } expect.fail('missed exception'); @@ -113,7 +113,7 @@ describe('Socks5 Connectivity', function () { await testConnection(cs.toString(), {}); } catch (err) { expect(err.name).to.equal('MongoServerSelectionError'); - expect(err.message).to.match(/Socket closed/); + expect(err.cause.message).to.match(/Socket closed/); return; } expect.fail('missed exception'); From 9d01de6c11543e07f58c81dc47781417eca95768 Mon Sep 17 00:00:00 2001 From: Warren James Date: Mon, 21 Aug 2023 16:25:33 -0400 Subject: [PATCH 31/37] test(NODE-5484): revert test changes and update errors tests --- .../client_side_encryption.prose.test.js | 14 ++++---------- .../mongodb-handshake/mongodb-handshake.test.ts | 2 +- test/integration/node-specific/errors.test.ts | 4 ++-- test/manual/socks5.test.ts | 10 +++++----- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/test/integration/client-side-encryption/client_side_encryption.prose.test.js b/test/integration/client-side-encryption/client_side_encryption.prose.test.js index 275b4eb1164..21c600bb690 100644 --- a/test/integration/client-side-encryption/client_side_encryption.prose.test.js +++ b/test/integration/client-side-encryption/client_side_encryption.prose.test.js @@ -8,12 +8,7 @@ const { dropCollection, APMEventCollector } = require('../shared'); const { EJSON } = BSON; const { LEGACY_HELLO_COMMAND } = require('../../mongodb'); -const { - MongoServerError, - MongoServerSelectionError, - MongoClient, - MongoRuntimeError -} = require('../../mongodb'); +const { MongoServerError, MongoServerSelectionError, MongoClient } = require('../../mongodb'); const { getEncryptExtraOptions } = require('../../tools/utils'); const { installNodeDNSWorkaroundHooks } = require('../../tools/runner/hooks/configuration'); const { coerce, gte } = require('semver'); @@ -1176,13 +1171,12 @@ describe('Client Side Encryption Prose Tests', metadata, function () { .insertOne({ encrypted: 'test' }) .catch(e => e); - expect(insertError).to.be.instanceOf(MongoRuntimeError); - expect(insertError).to.have.property('cause').that.is.instanceOf(MongoServerSelectionError); + expect(insertError).to.be.instanceOf(MongoServerSelectionError); // TODO(NODE-5296): check error.message once AggregateErrors are handled correctly - expect(insertError.cause, 'Error must contain ECONNREFUSED').to.satisfy( + expect(insertError, 'Error must contain ECONNREFUSED').to.satisfy( error => - /ECONNREFUSED/.test(error?.cause.message) || + /ECONNREFUSED/.test(error.message) || !!error.cause?.cause?.errors?.every(e => e.code === 'ECONNREFUSED') ); diff --git a/test/integration/mongodb-handshake/mongodb-handshake.test.ts b/test/integration/mongodb-handshake/mongodb-handshake.test.ts index def000a8d38..2e00d0e2e96 100644 --- a/test/integration/mongodb-handshake/mongodb-handshake.test.ts +++ b/test/integration/mongodb-handshake/mongodb-handshake.test.ts @@ -42,7 +42,7 @@ describe('MongoDB Handshake', () => { } else { expect(error).to.be.instanceOf(MongoServerSelectionError); } - expect(error.cause ?? error).to.match(/client metadata document must be less/); + expect(error).to.match(/client metadata document must be less/); }); }); diff --git a/test/integration/node-specific/errors.test.ts b/test/integration/node-specific/errors.test.ts index 2432addf53a..109e96a8255 100644 --- a/test/integration/node-specific/errors.test.ts +++ b/test/integration/node-specific/errors.test.ts @@ -28,14 +28,14 @@ describe('Error (Integration)', function () { it(`uses the AggregateError's message`, () => { const error = new AggregateError([new Error('non-empty')]); error.message = 'custom error message'; - const mongoError = new MongoError(error, { cause: error }); + const mongoError = new MongoError(MongoError.buildErrorMessage(error), { cause: error }); expect(mongoError.message).to.equal('custom error message'); }); }); it('sets the AggregateError to the cause property', () => { const error = new AggregateError([new Error('error 1')]); - const mongoError = new MongoError(error, { cause: error }); + const mongoError = new MongoError(MongoError.buildErrorMessage(error), { cause: error }); expect(mongoError.cause).to.equal(error); }); }); diff --git a/test/manual/socks5.test.ts b/test/manual/socks5.test.ts index 1d4fe96aa3b..a37907aff69 100644 --- a/test/manual/socks5.test.ts +++ b/test/manual/socks5.test.ts @@ -53,7 +53,7 @@ describe('Socks5 Connectivity', function () { await testConnection(cs.toString(), {}); } catch (err) { expect(err.name).to.equal('MongoServerSelectionError'); - expect(err.cause.message).to.match(/Received invalid Socks5 initial handshake/); + expect(err.message).to.match(/Received invalid Socks5 initial handshake/); return; } expect.fail('missed exception'); @@ -68,7 +68,7 @@ describe('Socks5 Connectivity', function () { }); } catch (err) { expect(err.name).to.equal('MongoServerSelectionError'); - expect(err.cause.message).to.match(/Received invalid Socks5 initial handshake/); + expect(err.message).to.match(/Received invalid Socks5 initial handshake/); return; } expect.fail('missed exception'); @@ -82,7 +82,7 @@ describe('Socks5 Connectivity', function () { await testConnection(cs.toString(), {}); } catch (err) { expect(err.name).to.equal('MongoServerSelectionError'); - expect(err.cause.message).to.match(/Received invalid Socks5 initial handshake/); + expect(err.message).to.match(/Received invalid Socks5 initial handshake/); return; } expect.fail('missed exception'); @@ -96,7 +96,7 @@ describe('Socks5 Connectivity', function () { }); } catch (err) { expect(err.name).to.equal('MongoServerSelectionError'); - expect(err.cause.message).to.match(/Received invalid Socks5 initial handshake/); + expect(err.message).to.match(/Received invalid Socks5 initial handshake/); return; } expect.fail('missed exception'); @@ -113,7 +113,7 @@ describe('Socks5 Connectivity', function () { await testConnection(cs.toString(), {}); } catch (err) { expect(err.name).to.equal('MongoServerSelectionError'); - expect(err.cause.message).to.match(/Socket closed/); + expect(err.message).to.match(/Socket closed/); return; } expect.fail('missed exception'); From 25ad3a41bde59bc0ad8b96b4bbfe63baf7dbd407 Mon Sep 17 00:00:00 2001 From: Warren James Date: Mon, 21 Aug 2023 16:25:59 -0400 Subject: [PATCH 32/37] fix(NODE-5484): fix error message construction --- src/error.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/error.ts b/src/error.ts index bbeafc3b9a9..11203a9a9ae 100644 --- a/src/error.ts +++ b/src/error.ts @@ -144,7 +144,7 @@ export class MongoError extends Error { * @public **/ constructor(message: string, options?: { cause?: Error }) { - super(MongoError.buildErrorMessage(message), options); + super(message, options); this[kErrorLabels] = new Set(); } @@ -1036,7 +1036,9 @@ export class MongoSystemError extends MongoError { **/ constructor(message: string, reason: TopologyDescription) { if (reason && reason.error) { - super(message, { cause: reason.error }); + super(MongoError.buildErrorMessage(reason.error.message || reason.error), { + cause: reason.error + }); } else { super(message); } From b0d687a597edb10b85927dc3d76af68cb47bcf4c Mon Sep 17 00:00:00 2001 From: Warren James Date: Mon, 21 Aug 2023 16:28:06 -0400 Subject: [PATCH 33/37] style(NODE-5484): remove comment --- .../client-side-encryption/client_side_encryption.prose.test.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/integration/client-side-encryption/client_side_encryption.prose.test.js b/test/integration/client-side-encryption/client_side_encryption.prose.test.js index 21c600bb690..5edd62b3e76 100644 --- a/test/integration/client-side-encryption/client_side_encryption.prose.test.js +++ b/test/integration/client-side-encryption/client_side_encryption.prose.test.js @@ -1179,8 +1179,6 @@ describe('Client Side Encryption Prose Tests', metadata, function () { /ECONNREFUSED/.test(error.message) || !!error.cause?.cause?.errors?.every(e => e.code === 'ECONNREFUSED') ); - - //expect(insertError.cause).to.be.instanceOf(MongoServerSelectionError); }); }); From 2cfa31dd4523ac52e51db75d20e1e7ef68f8e2e4 Mon Sep 17 00:00:00 2001 From: Warren James Date: Mon, 21 Aug 2023 16:30:00 -0400 Subject: [PATCH 34/37] test(NODE-5484): revert unit test --- test/unit/assorted/wire_version.test.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/test/unit/assorted/wire_version.test.js b/test/unit/assorted/wire_version.test.js index 468d7a6a5f6..7607ff09b7c 100644 --- a/test/unit/assorted/wire_version.test.js +++ b/test/unit/assorted/wire_version.test.js @@ -2,11 +2,7 @@ const mock = require('../../tools/mongodb-mock/index'); const { expect } = require('chai'); -const { - MongoServerSelectionError, - MongoCompatibilityError, - MongoClient -} = require('../../mongodb'); +const { MongoServerSelectionError, MongoClient } = require('../../mongodb'); const { isHello } = require('../../mongodb'); const minCompatErrMsg = `minimum wire version ${ @@ -53,8 +49,7 @@ describe('Wire Protocol Version', () => { expect.fail('should fail to select server!'); } catch (error) { expect(error).to.be.instanceOf(MongoServerSelectionError); - expect(error.cause).to.be.instanceOf(MongoCompatibilityError); - expect(error.cause).to.have.property('message').that.includes(minCompatErrMsg); + expect(error).to.have.property('message').that.includes(minCompatErrMsg); } }); }); @@ -72,8 +67,7 @@ describe('Wire Protocol Version', () => { expect.fail('should fail to select server!'); } catch (error) { expect(error).to.be.instanceOf(MongoServerSelectionError); - expect(error.cause).to.be.instanceOf(MongoCompatibilityError); - expect(error.cause).to.have.property('message').that.includes(maxCompatErrMsg); + expect(error).to.have.property('message').that.includes(maxCompatErrMsg); } }); }); From b818f3ba646744f79254df6958411af938ce8f68 Mon Sep 17 00:00:00 2001 From: Warren James Date: Mon, 21 Aug 2023 16:40:57 -0400 Subject: [PATCH 35/37] test(NODE-5484): revert test change --- .../client-side-encryption/client_side_encryption.prose.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/client-side-encryption/client_side_encryption.prose.test.js b/test/integration/client-side-encryption/client_side_encryption.prose.test.js index 5edd62b3e76..b25e9d35454 100644 --- a/test/integration/client-side-encryption/client_side_encryption.prose.test.js +++ b/test/integration/client-side-encryption/client_side_encryption.prose.test.js @@ -1265,7 +1265,7 @@ describe('Client Side Encryption Prose Tests', metadata, function () { ); expect(error, 'Error MUST contain ECONNREFUSED information').to.satisfy( error => - /ECONNREFUSED/.test(error.cause.message) || + /ECONNREFUSED/.test(error.message) || !!error.cause?.cause?.errors?.every(e => e.code === 'ECONNREFUSED') ); }); From d24285b1fbb4b64076bd3665c6927927b16cd1a6 Mon Sep 17 00:00:00 2001 From: Warren James Date: Tue, 22 Aug 2023 14:07:54 -0400 Subject: [PATCH 36/37] test(NODE-5484): update tests to accept options --- test/unit/error.test.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/unit/error.test.ts b/test/unit/error.test.ts index f57aef9b06b..18c0dd054d9 100644 --- a/test/unit/error.test.ts +++ b/test/unit/error.test.ts @@ -90,16 +90,17 @@ describe('MongoErrors', () => { expect(err).to.be.an.instanceof(Error); expect(err.name).to.equal('MongoError'); expect(err.message).to.equal(errorMessage); + expect(err).to.have.property('cause').that.is.undefined; }); - it('should accept an Error object', () => { + it('should accept an Error object and set cause', () => { const errorMessage = 'A test error'; const inputError = new Error(errorMessage); - const err = new MongoError(inputError); + const err = new MongoError('', { cause: inputError }); expect(err).to.be.an.instanceof(Error); expect(err.name).to.equal('MongoError'); expect(err.message).to.equal(errorMessage); - expect(err).to.not.have.property('cause'); + expect(err).to.have.property('cause').that.is.instanceOf(Error); }); }); From c942e9f783ba5df2c90a1038bf5676f2a8364735 Mon Sep 17 00:00:00 2001 From: Warren James Date: Tue, 22 Aug 2023 14:24:47 -0400 Subject: [PATCH 37/37] test(NODE-5484): migrate MongoError.buildErrorMessage tests to unit tests --- test/integration/node-specific/errors.test.ts | 39 +------------- test/unit/error.test.ts | 52 +++++++++++++++++-- 2 files changed, 49 insertions(+), 42 deletions(-) diff --git a/test/integration/node-specific/errors.test.ts b/test/integration/node-specific/errors.test.ts index 109e96a8255..c0890083eb9 100644 --- a/test/integration/node-specific/errors.test.ts +++ b/test/integration/node-specific/errors.test.ts @@ -1,45 +1,8 @@ import { expect } from 'chai'; -import { MongoClient, MongoError, MongoServerSelectionError } from '../../mongodb'; +import { MongoClient, MongoServerSelectionError } from '../../mongodb'; describe('Error (Integration)', function () { - describe('AggregateErrors', function () { - for (const { errors, message } of [ - { - errors: [], - message: - 'AggregateError has an empty errors array. Please check the `cause` property for more information.' - }, - { errors: [new Error('message 1')], message: 'message 1' }, - { - errors: [new Error('message 1'), new Error('message 2')], - message: 'message 1, message 2' - } - ]) { - it(`constructs the message properly with an array of ${errors.length} errors`, () => { - const error = new AggregateError(errors); - const mongoError = new MongoError(message, { cause: error }); - - expect(mongoError.message).to.equal(message); - }); - } - - context('when the message on the AggregateError is non-empty', () => { - it(`uses the AggregateError's message`, () => { - const error = new AggregateError([new Error('non-empty')]); - error.message = 'custom error message'; - const mongoError = new MongoError(MongoError.buildErrorMessage(error), { cause: error }); - expect(mongoError.message).to.equal('custom error message'); - }); - }); - - it('sets the AggregateError to the cause property', () => { - const error = new AggregateError([new Error('error 1')]); - const mongoError = new MongoError(MongoError.buildErrorMessage(error), { cause: error }); - expect(mongoError.cause).to.equal(error); - }); - }); - it('NODE-5296: handles aggregate errors from dns lookup', async function () { const error = await MongoClient.connect('mongodb://localhost:27222', { serverSelectionTimeoutMS: 1000 diff --git a/test/unit/error.test.ts b/test/unit/error.test.ts index 18c0dd054d9..ebaa0e9281c 100644 --- a/test/unit/error.test.ts +++ b/test/unit/error.test.ts @@ -90,16 +90,16 @@ describe('MongoErrors', () => { expect(err).to.be.an.instanceof(Error); expect(err.name).to.equal('MongoError'); expect(err.message).to.equal(errorMessage); - expect(err).to.have.property('cause').that.is.undefined; + expect(err).to.not.have.property('cause'); }); - it('should accept an Error object and set cause', () => { + it('should accept options and set cause property', () => { const errorMessage = 'A test error'; const inputError = new Error(errorMessage); - const err = new MongoError('', { cause: inputError }); + const err = new MongoError('test', { cause: inputError }); expect(err).to.be.an.instanceof(Error); expect(err.name).to.equal('MongoError'); - expect(err.message).to.equal(errorMessage); + expect(err.message).to.equal('test'); expect(err).to.have.property('cause').that.is.instanceOf(Error); }); }); @@ -662,4 +662,48 @@ describe('MongoErrors', () => { }); }); }); + + describe('MongoError#buildErrorMessage', function () { + context( + 'when passed an AggregateError with an empty message and non-empty errors array', + function () { + it('returns error messages separated by commas', function () { + const aggErr = new AggregateError([new Error('message 1'), new Error('message 2')], ''); + expect(MongoError.buildErrorMessage(aggErr)).to.deep.equal('message 1, message 2'); + }); + } + ); + context('when passed an AggregateError with a non-empty message', function () { + it('returns message field', function () { + const aggErr = new AggregateError( + [new Error('message 1'), new Error('message 2')], + 'aggErr' + ); + expect(MongoError.buildErrorMessage(aggErr)).to.deep.equal(aggErr.message); + }); + }); + context( + 'when passed an AggregateError with an empty errors array and empty message', + function () { + it('returns string instructing user to check `cause` property', function () { + const aggErr = new AggregateError([], ''); + expect(MongoError.buildErrorMessage(aggErr)).to.match( + /Please check the `cause` property for more information./ + ); + }); + } + ); + context('when passed an Error that is not an AggregateError', function () { + it("returns the Error's message property", function () { + const err = new Error('error message'); + expect(MongoError.buildErrorMessage(err)).to.deep.equal('error message'); + }); + }); + + context('when passed a string', function () { + it('returns the string', function () { + expect(MongoError.buildErrorMessage('message')).to.deep.equal('message'); + }); + }); + }); });