-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(NODE-5999): Change TopologyDescription.error type to MongoError #4028
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
Conversation
82fa338 to
5f87446
Compare
| } | ||
|
|
||
| get error(): MongoServerError | null { | ||
| get error(): MongoError | null { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is technically public. I think this change is okay to make, because we usually permit breaking TS fixes in non-major releases. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is an expanded type considered a breaking change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm on second thought - if we had made this change before c023242, I don't think this would have been breaking. but since MongoServerError is no longer assignable to MongoError, it's now breaking to make this change? But I still think that's okay. This is a correctness fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MongoServerError inherits from MongoError, so MongoServerError can be assigned to MongoError, but not the other way around. This is why we had to make this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interface Foo {
name: string;
}
interface Bar extends Foo {
age: number;
}
const document: Bar = { name: 'bumpy', age: 7 };If Bar is changed to Foo, this code fails to compile. That's why this change is potentially problematic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm I see. Should we wait until the next major version to make this change?
Description
Expand type descriptions for certain uses of
MongoServerErrortoMongoErrorand remove casting.What is changing?
Server.error,ServerDescription.error,ServerDescriptionOptions.errorandTopologyDescription.errorto beMongoError | nullinstead ofMongoServerError | null.markServerUnknownmethod to beMongoErrorinstead ofMongoServerErrorIs there new documentation needed for these changes?
Yes, there is a change being made to the public
TopologyDescriptionclass (the error property of that class specifically).What is the motivation for this change?
Before NODE-5988 merged, the type signature of
MongoServerErrorwas identical toMongoError, and prior to this PR, multiple places in the driver,MongoServerErrorwas used imprecisely.In the
server.handleErrormethod and its test file, it's noted that the following are errors the server can "handle" or mark as unknown properly:MongoServerErrorMongoErrorwith aMongoErrorLabel.HandshakeErrorMongoNetworkErrorthat's not aMongoNetworkRuntimeError.Therefore,
MongoServerErroris the incorrect type for themarkServerUnknownmethod called withinserver.handleErrormethod, and the type was expanded toMongoError. This trickles up toServer,ServerDescription,ServerDescriptionOptions, andTopologyDescription.error.Release Highlight
TopologyDescription.error type is MongoError
Important
The
TopologyDescription.errorproperty type is nowMongoErrorrather thanMongoServerError.This type change is a correctness fix.
Before this change, the following errors that were not instances of
MongoServerErrorwere already passed intoTopologyDescription.errorat runtime:MongoNetworkError(excludingMongoNetworkRuntimeError)MongoErrorwith aMongoErrorLabel.HandshakeErrorlabelDouble check the following
npm run check:lintscripttype(NODE-xxxx)[!]: descriptionfeat(NODE-1234)!: rewriting everything in coffeescript