-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Unknown
-
None
-
Affects Version/s: None
-
Component/s: Error
As a Node driver engineer,
I want to store error information in exactly one place,
So that we don't need to be responsible for maintaining the server information in two places.
The server's actual error is stored both as the errorResponse field on the MongoServerError and has every property copied onto the server error (see https://github.com/mongodb/node-mongodb-native/blob/8ab5d19bee52bf1f0bc24a76586375a4825190f9/src/error.ts#L226).
Why this needs a major
Typed error responses are blocked by this. Connection.command can type any ok:1 response via responseType, but MongoServerError carries [key: string]: any, which cannot be narrowed while the copy loop exists. See Neal's comment on NODE-7779.
User impact
Removes top-level access to every server error field: err.keyPattern, err.keyValue, err.codeName, err.writeErrors. Migration is err.errorResponse.<field>, which is the spec-mandated path and works today.
Unknowns
n/a
Acceptance Criteria
Implementation Requirements
- Remove the logic that copies keys from the server error onto the MongoServerError and instead only provide the errorResponse field.
- Decide the fate of codeName, writeConcernError, errInfo and ok - these are declared on the class but assigned only by the copy loop, so they become undefined unless explicitly reassigned or removed from the declaration.
Documentation Requirements
- Remove API docs for MongoServerError enumerable keys