-
Notifications
You must be signed in to change notification settings - Fork 1.8k
refactor(NODE-3405): implement MongoRuntimeError children #2913
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
refactor(NODE-3405): implement MongoRuntimeError children #2913
Conversation
src/cmap/connection_pool.ts
Outdated
} | ||
if (!waitQueueMember[kCancelled]) { | ||
waitQueueMember.callback(new MongoDriverError('connection pool closed')); | ||
waitQueueMember.callback(new MongoResourceClosedError('Connection pool closed')); |
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.
Should we just go ahead and create a MongoConnectionPoolClosedError
? It feels somewhat out of place having the more generic form of this error directly instantiated.
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.
Sounds good! Leaving a TODO comment with a new ticket for this.
In general, I think it might be worth to make specific ClosedErrors for things that users will commonly run into (servers, streams, etc) and leaving MongoResourceClosedError
as the general use case.
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.
In that case, this might be worth discussing with the team to get a better idea of the more common cases
src/sdam/server.ts
Outdated
[STATE_CLOSING]: [STATE_CLOSING, STATE_CLOSED] | ||
}); | ||
|
||
const SERVER_CLOSED_ERROR = 'Server is closed'; |
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.
In general, I think that when we have a resource that has been closed, the message should be of the form
'<resource type> has been closed'
That's a personal preference, but I think having it be more consistent would be better for error message readability. I'll flag other instances of this.
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.
I'm a little hesitant to use the past tense in this error message because it might imply that the server has been closed as a result of this operation rather than conveying the current state of the server. Happy to make this change for now and see what everyone else thinks; maybe I'm being a little too semantic.
7937f49
to
7f7575d
Compare
src/gridfs/upload.ts
Outdated
if (stream.state.aborted) { | ||
if (typeof callback === 'function') { | ||
callback(new MongoDriverError('this stream has been aborted')); | ||
callback(new MongoStreamClosedError('Stream has been aborted')); |
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.
In the same vein as this comment on NODE-3421 we may want to consider adding a default message for MongoStreamClosedError with an optional message parameter for cases where more information is needed
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.
I didn't leave a comment on every line regarding transaction errors, but see my comment regarding reconsidering how we subclass these so that we can differentiate between incorrect usage from the user's side vs unexpected driver state
src/change_stream.ts
Outdated
AnyError, | ||
isResumableError, | ||
MongoDriverError, | ||
MongoStreamClosedError |
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.
As a general question to the team, do we want to conflate generic streams with change streams in our error reporting? Our change streams aren't really node streams in the sense that they don't extend from any of the base node streams. I could go either way, but my thought is that there could be some merit in differentiating "steam closed" vs "change stream closed" @nbbeeken @emadum Thoughts?
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.
Seems worthy of differentiating, I would imagine we'd only need use of MongoChangeStreamError, but there may be instances of Streams related errors, unless they stop something from continuing in our code I would say node stream errors should be bubbled up as is.
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.
The initial goal we had was to use MongoStreamClosedError
between GridFSStream and ChangeStream to prevent creating two similar errors. If it's worth differentiating we could just split them down into GridFSStreamClosed
and ChangeStreamClosed
.
src/sessions.ts
Outdated
startTransaction(options?: TransactionOptions): void { | ||
if (this[kSnapshotEnabled]) { | ||
throw new MongoDriverError('Transactions are not allowed with snapshot sessions'); | ||
throw new MongoTransactionError('Transactions are not allowed with snapshot sessions'); |
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 more of an API error - probably the compatibility one, because in order to get here, the user needs to intentionally start a snapshot session and then try to start a transaction on it
src/sessions.ts
Outdated
assertAlive(this); | ||
if (this.inTransaction()) { | ||
throw new MongoDriverError('Transaction already in progress'); | ||
throw new MongoAPIError('Transaction already in progress'); |
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.
Since we are moving MongoTransactionError to be child of MongoAPIError, should we change this to MongoTransactionError and just go ahead and move MongoTransactionError to be a child of MongoAPIError in this PR?
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.
If not, we should also mark this for replacement in NODE-3485
9631286
to
0aa6910
Compare
4722cc8
to
3264b92
Compare
src/gridfs/upload.ts
Outdated
import type { GridFSBucket } from './index'; | ||
import type { GridFSFile } from './download'; | ||
import type { WriteConcernOptions } from '../write_concern'; | ||
import type { Collection } from '../collection'; |
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.
revert the import sorting here
src/sdam/topology.ts
Outdated
drainWaitQueue( | ||
topology[kWaitQueue], | ||
new MongoDriverError('Topology is closed, please connect') | ||
new MongoTopologyClosedError(`${TOPOLOGY_CLOSED_ERROR}, please connect`) |
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.
I think we can leave this error to be without message like the usage above
src/error.ts
Outdated
*/ | ||
export class MongoServerClosedError extends MongoAPIError { | ||
constructor(message: string) { | ||
constructor(message = 'Server has been closed') { |
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.
Are we all in agreement on tense? super bikeshedding but present/imperative seems more ideal
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.
@dariakp @emadum @W-A-James? Personally, I'm in favor of present tense but happy to defer.
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.
My vote would also be for using present/imperative.
src/cmap/connection_pool.ts
Outdated
} | ||
if (!waitQueueMember[kCancelled]) { | ||
waitQueueMember.callback(new MongoDriverError('connection pool closed')); | ||
waitQueueMember.callback(new MongoAPIError('Connection pool closed')); |
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.
I am not convinced this is an API method, the entire class is marked internal, so this is unlikely to be due to a user error
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.
LGTM 👍
src/error.ts
Outdated
*/ | ||
export class MongoServerClosedError extends MongoAPIError { | ||
constructor(message: string) { | ||
constructor(message = 'Server has been closed') { |
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.
My vote would also be for using present/imperative.
src/operations/common_functions.ts
Outdated
// Did the user destroy the topology | ||
if (getTopology(db).isDestroyed()) | ||
return callback(new MongoDriverError('topology was destroyed')); | ||
return callback(new MongoTopologyClosedError('Topology was destroyed')); |
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.
return callback(new MongoTopologyClosedError('Topology was destroyed')); | |
return callback(new MongoTopologyClosedError('Topology is destroyed')); |
If we're going to update messages to present tense, can do this one as well.
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.
We can also rely on the default string here
@dariakp re: this comment You're totally right. I'm going to leave a TODO pointing toward NODE-3483 which introduces MongoConnectionPoolClosedError as a child of RuntimeError. Also going to revert this to MongoRuntimeError for the time being. |
Description
Replace instances of MongoDriverError with the appropriate children of MongoRuntimeError, listed below, as described in docs/errors.md.
Children of MongoRuntimeError used: