-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix(NODE-5999): Change TopologyDescription.error type to MongoError #4028
Conversation
82fa338
to
5f87446
Compare
@@ -307,13 +307,13 @@ export class TopologyDescription { | |||
); | |||
} | |||
|
|||
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
MongoServerError
toMongoError
and remove casting.What is changing?
Server.error
,ServerDescription.error
,ServerDescriptionOptions.error
andTopologyDescription.error
to beMongoError | null
instead ofMongoServerError | null
.markServerUnknown
method to beMongoError
instead ofMongoServerError
Is there new documentation needed for these changes?
Yes, there is a change being made to the public
TopologyDescription
class (the error property of that class specifically).What is the motivation for this change?
Before NODE-5988 merged, the type signature of
MongoServerError
was identical toMongoError
, and prior to this PR, multiple places in the driver,MongoServerError
was used imprecisely.In the
server.handleError
method and its test file, it's noted that the following are errors the server can "handle" or mark as unknown properly:MongoServerError
MongoError
with aMongoErrorLabel.HandshakeError
MongoNetworkError
that's not aMongoNetworkRuntimeError.
Therefore,
MongoServerError
is the incorrect type for themarkServerUnknown
method called withinserver.handleError
method, and the type was expanded toMongoError
. This trickles up toServer
,ServerDescription
,ServerDescriptionOptions
, andTopologyDescription.error
.Release Highlight
TopologyDescription.error type is MongoError
Important
The
TopologyDescription.error
property type is nowMongoError
rather thanMongoServerError
.This type change is a correctness fix.
Before this change, the following errors that were not instances of
MongoServerError
were already passed intoTopologyDescription.error
at runtime:MongoNetworkError
(excludingMongoNetworkRuntimeError
)MongoError
with aMongoErrorLabel.HandshakeError
labelDouble check the following
npm run check:lint
scripttype(NODE-xxxx)[!]: description
feat(NODE-1234)!: rewriting everything in coffeescript