Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(NODE-5484)!: mark MongoError for internal use and remove Node14 cause assignment logic #3800

Merged
merged 39 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
a8653ba
feat(NODE-5484)!: make MongoError constructors internal and remove No…
W-A-James Aug 7, 2023
d504317
fix(NODE-5484): only remove unnecessary options
W-A-James Aug 7, 2023
d2012c5
fix(NODE-5484): make constructors internal
W-A-James Aug 7, 2023
ea5ea72
test(NODE-5484): add unit tests to check that MongoCrypt Errors subcl…
W-A-James Aug 7, 2023
53491bd
docs(NODE-5484): start docs update
W-A-James Aug 7, 2023
55f487c
fix(NODE-5484): remove unneeded type
W-A-James Aug 7, 2023
ccb0866
docs(NODE-5484): update docs
W-A-James Aug 7, 2023
be7c2f9
docs(NODE-5484): fix diagram
W-A-James Aug 7, 2023
85b02a5
docs(NODE-5484): fix diagram
W-A-James Aug 7, 2023
4b1ad15
docs(NODE-5484): clean up mermaid code
W-A-James Aug 7, 2023
aac86bc
fix(NODE-5484): fix inheritance
W-A-James Aug 7, 2023
48f7e15
fix(NODE-5484): undo unneeded change
W-A-James Aug 7, 2023
6618575
fix(NODE-5484): override cause field
W-A-James Aug 8, 2023
ae76093
Merge branch 'main' into NODE-5484
W-A-James Aug 8, 2023
1d08c4b
test(NODE-5484): fix test
W-A-James Aug 8, 2023
2a58338
test(NODE-5484): update test
W-A-James Aug 8, 2023
12d8aa7
test(NODE-5484): remove duplicate describe block
W-A-James Aug 8, 2023
484519d
test(NODE-5484): fix unit test
W-A-James Aug 8, 2023
d8ee589
docs(NODE-5484): update MongoError API docs
W-A-James Aug 10, 2023
0838e97
docs(NODE-5484): Refine docs
W-A-James Aug 10, 2023
7120ef7
docs(NODE-5484): formatting and wording
W-A-James Aug 10, 2023
414d53a
Update etc/notes/errors.md
W-A-James Aug 15, 2023
b51ad79
docs(NODE-5484): update docs
W-A-James Aug 15, 2023
161d32b
Update etc/notes/errors.md
W-A-James Aug 16, 2023
564d117
docs(NODE-5484): update wording
W-A-James Aug 16, 2023
aaa2ebe
fix(NODE-5484): update constructors to not take error
W-A-James Aug 16, 2023
4ca5acd
test(NODE-5484): fix test assertions
W-A-James Aug 16, 2023
6511534
test(NODE-5484): start fixing csfle tests
W-A-James Aug 16, 2023
65c7767
fix(NODE-5484): Update error constructor calls and csfle prose tests
W-A-James Aug 18, 2023
4ec65c2
test(NODE-5484): update assertion
W-A-James Aug 21, 2023
56920da
test(NODE-5484): Fix test assertions
W-A-James Aug 21, 2023
9d01de6
test(NODE-5484): revert test changes and update errors tests
W-A-James Aug 21, 2023
25ad3a4
fix(NODE-5484): fix error message construction
W-A-James Aug 21, 2023
b0d687a
style(NODE-5484): remove comment
W-A-James Aug 21, 2023
2cfa31d
test(NODE-5484): revert unit test
W-A-James Aug 21, 2023
b818f3b
test(NODE-5484): revert test change
W-A-James Aug 21, 2023
d24285b
test(NODE-5484): update tests to accept options
W-A-James Aug 22, 2023
c942e9f
test(NODE-5484): migrate MongoError.buildErrorMessage tests to unit t…
W-A-James Aug 22, 2023
7553a6d
Merge branch 'main' into NODE-5484
baileympearson Aug 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 30 additions & 23 deletions etc/notes/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- [`MongoNetworkError`](#MongoNetworkError)
- [`MongoServerError`](#MongoServerError)
- [`MongoSystemError`](#MongoSystemError)
- [`MongoCryptError`](#MongoCryptError)
- [Test Plan](#Test-Plan)
- [`MongoAPIError`](#MongoAPIError-1)
- [`MongoInvalidArgumentError`](#MongoInvalidArgumentError-1)
Expand All @@ -32,37 +33,27 @@
## 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`

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
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

style MongoError 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:
Expand All @@ -71,6 +62,7 @@ Children of `MongoError` include:
- [`MongoNetworkError`](#MongoNetworkError)
- [`MongoServerError`](#MongoServerError)
- [`MongoSystemError`](#MongoSystemError)
- [`MongoCryptError`](#MongoCryptError)

### `MongoDriverError`

Expand Down Expand Up @@ -144,6 +136,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than linking the package, maybe we could just say that these errors are thrown from the driver's CSFLE logic?


- #### MongoCryptInvalidArgumentError
- Thrown when an invalid argument has been provided to an encryption API
- #### MongoCryptInvalidCreateDataKeyError
- Thrown when `ClientEncryption.createEncryptedCollection()` failed to create data keys
- #### MongoCryptInvalidCreateEncryptedCollectionError
- Thrown when `ClientEncryption.createEncryptedCollection()` failed to create a collection
- #### MongoCryptInvalidCreateAzureKMSRequestError
- Thrown when `mongodb-client-encryption` failed to auto-refresh Azure KMS credentials
- #### MongoCryptKMSRequestNetworkTimeoutError
- Thrown when `mongodb-client-encryption` times out when fetching KMS credentials

W-A-James marked this conversation as resolved.
Show resolved Hide resolved
## Test Plan

The test plan consists of a series of prose tests.
Expand Down
12 changes: 11 additions & 1 deletion src/bulk/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,17 @@ export class MongoBulkWriteError extends MongoServerError {
writeErrors: OneOrMore<WriteError> = [];
err?: WriteConcernError;

/** Creates a new MongoBulkWriteError */
/**
* **Do not use this constructor!**
*
* Meant for internal use only.
*
* @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.
*
* @public
**/
constructor(
error:
| { message: string; code: number; writeErrors?: WriteError[] }
Expand Down
63 changes: 57 additions & 6 deletions src/client-side-encryption/errors.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
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 {
/** @internal */
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. This constructor is
* not subject to semantic versioning compatiblity guarantees and may change at any time.
*
* @public
**/
constructor(message: string, options: { cause?: Error } = {}) {
super(message, options);
}
Expand All @@ -21,7 +32,17 @@ export class MongoCryptError extends Error {
* An error indicating an invalid argument was provided to an encryption API.
*/
export class MongoCryptInvalidArgumentError extends MongoCryptError {
/** @internal */
/**
* **Do not use this constructor!**
*
* Meant for internal use only.
*
* @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.
*
* @public
**/
constructor(message: string) {
super(message);
}
Expand All @@ -36,7 +57,17 @@ export class MongoCryptInvalidArgumentError extends MongoCryptError {
*/
export class MongoCryptCreateDataKeyError extends MongoCryptError {
encryptedFields: Document;
/** @internal */
/**
* **Do not use this constructor!**
*
* Meant for internal use only.
*
* @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.
*
* @public
**/
constructor(encryptedFields: Document, { cause }: { cause: Error }) {
super(`Unable to complete creating data keys: ${cause.message}`, { cause });
this.encryptedFields = encryptedFields;
Expand All @@ -53,7 +84,17 @@ export class MongoCryptCreateDataKeyError extends MongoCryptError {
*/
export class MongoCryptCreateEncryptedCollectionError extends MongoCryptError {
encryptedFields: Document;
/** @internal */
/**
* **Do not use this constructor!**
*
* Meant for internal use only.
*
* @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.
*
* @public
**/
constructor(encryptedFields: Document, { cause }: { cause: Error }) {
super(`Unable to create collection: ${cause.message}`, { cause });
this.encryptedFields = encryptedFields;
Expand All @@ -71,7 +112,17 @@ 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!**
*
* Meant for internal use only.
*
* @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.
*
* @public
**/
constructor(message: string, body?: Document) {
super(message);
this.body = body;
Expand Down
44 changes: 44 additions & 0 deletions src/cmap/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ export class PoolClosedError extends MongoDriverError {
/** The address of the connection pool */
address: string;

/**
* **Do not use this constructor!**
*
* Meant for internal use only.
*
* @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.
*
* @public
**/
constructor(pool: ConnectionPool) {
super('Attempted to check out a connection from closed connection pool');
this.address = pool.address;
Expand All @@ -27,6 +38,17 @@ export class PoolClearedError extends MongoNetworkError {
/** The address of the connection pool */
address: string;

/**
* **Do not use this constructor!**
*
* Meant for internal use only.
*
* @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.
*
* @public
**/
constructor(pool: ConnectionPool, message?: string) {
const errorMessage = message
? message
Expand All @@ -47,6 +69,17 @@ export class PoolClearedError extends MongoNetworkError {
* @category Error
*/
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. This constructor is
* not subject to semantic versioning compatiblity guarantees and may change at any time.
*
* @public
**/
constructor(pool: ConnectionPool) {
super(pool, `Connection to ${pool.address} interrupted due to server monitor timeout`);
}
Expand All @@ -64,6 +97,17 @@ export class WaitQueueTimeoutError extends MongoDriverError {
/** The address of the connection pool */
address: string;

/**
* **Do not use this constructor!**
*
* Meant for internal use only.
*
* @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.
*
* @public
**/
constructor(message: string, address: string) {
super(message);
this.address = address;
Expand Down
Loading