-
Type: Task
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
Use Case
As a driver engineer,
I want our errors to properly support the `cause` property
So that we can provide actionable errors to users.
User Impact
Should be minimal - users shouldn't be constructing MongoErrors themselves.
Dependencies
- n/a
Unknowns
- Should we take this opportunity to mark the constructors of our errors internal?
Yes- No, this will outright remove documentation from the constructors, but users will still be allowed to construct them. Rather, we should leave the constructors public but add tsdoc comments that explain that they are not intended for users and are not covered under semver
Acceptance Criteria
Implementation Requirements
- Adjust the constructor of `MongoError` to `constructor(message: string, options: { cause?: Error })` (this matches the official Error constructor)
- Adjust subclasses of MongoError to properly call `super` with the required parameters.
- Narrow the type of the `cause` property to an `Error` for our drivers' errors.
- Remove Node14 logic to attach the cause to MongoError manually in the constructor and remove the `cause` property from the MongoError class.
Make the constructors of all our errors internal (see open question).- Update doc comments on Error constructors (see open question)
- Make `MongoCryptError` a subclass of MongoError
- This was deferred until the constructor of `MongoError` properly supports a cause.
Testing Requirements
- Add tests asserting that each MongoCryptError is a subclass of MongoError.
Documentation Requirements
- Update `etc/notes/Errors.md` with new errors
- Add release note mentioning that MongoCryptError is now subclassing MongoError
- Add release note mentioning that constructors will be made private
- Ensure that the constructors of our errors are public but the API documentation explicitly states that they are not for external use.
Follow Up Requirements
- File a ticket to revisit how we document and expose classes which have internal constructors
- is depended on by
-
MONGOSH-1578 Investigate changes in NODE-5484: Add Node16+ support for the `cause` property in errors
- Closed