Skip to content

Conversation

andymina
Copy link
Contributor

Description

Replace instances of MongoDriverError with the appropriate children of MongoRuntimeError, listed below, as described in docs/errors.md.

Children of MongoRuntimeError used:

  • MongoTransactionError
  • MongoExpiredSessionError
  • MongoKerberosError
  • MongoResourceClosedError
  • MongoServerClosedError
  • MongoStreamClosedError
  • MongoTopologyClosedError

@andymina andymina self-assigned this Jul 20, 2021
@andymina andymina added the wip label Jul 20, 2021
@andymina andymina changed the title refactor(NODE-3405): replace MongoDriverError where appropriate refactor(NODE-3405): implement MongoRuntime children Jul 20, 2021
@andymina andymina requested a review from W-A-James July 20, 2021 17:47
@andymina andymina removed the wip label Jul 20, 2021
@andymina andymina marked this pull request as ready for review July 20, 2021 17:47
@W-A-James W-A-James added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Jul 21, 2021
}
if (!waitQueueMember[kCancelled]) {
waitQueueMember.callback(new MongoDriverError('connection pool closed'));
waitQueueMember.callback(new MongoResourceClosedError('Connection pool closed'));
Copy link
Contributor

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.

Copy link
Contributor Author

@andymina andymina Jul 21, 2021

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.

Copy link
Contributor

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

[STATE_CLOSING]: [STATE_CLOSING, STATE_CLOSED]
});

const SERVER_CLOSED_ERROR = 'Server is closed';
Copy link
Contributor

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.

Copy link
Contributor Author

@andymina andymina Jul 21, 2021

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.

@andymina andymina changed the title refactor(NODE-3405): implement MongoRuntime children refactor(NODE-3405): implement MongoRuntimeError children Jul 22, 2021
@andymina andymina requested a review from W-A-James July 22, 2021 18:07
@andymina andymina force-pushed the NODE-3405/implement-MongoRuntimeError-children branch from 7937f49 to 7f7575d Compare July 26, 2021 15:14
if (stream.state.aborted) {
if (typeof callback === 'function') {
callback(new MongoDriverError('this stream has been aborted'));
callback(new MongoStreamClosedError('Stream has been aborted'));
Copy link
Contributor

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

@W-A-James
Copy link
Contributor

@andymina There is a TODO that points to this ticket in src/db.ts: 752. Feel free to point that to NODE-3484 instead

@andymina
Copy link
Contributor Author

@andymina There is a TODO that points to this ticket in src/db.ts: 752. Feel free to point that to NODE-3484 instead

I removed the TODOs here because I realized this is the validateDatabaseName() mentioned in NODE-3483. I left a TODO pointing to NODE-3483 for this entire function.

@W-A-James W-A-James requested review from W-A-James and removed request for W-A-James July 26, 2021 18:31
@andymina andymina requested a review from W-A-James July 26, 2021 19:40
@W-A-James W-A-James added Team Review Needs review from team and removed Primary Review In Review with primary reviewer, not yet ready for team's eyes labels Jul 26, 2021
@W-A-James W-A-James requested review from dariakp and nbbeeken July 26, 2021 19:46
Copy link
Contributor

@dariakp dariakp left a 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

AnyError,
isResumableError,
MongoDriverError,
MongoStreamClosedError
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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');
Copy link
Contributor

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');
Copy link
Contributor

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?

Copy link
Contributor

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

@andymina andymina added wip and removed Team Review Needs review from team labels Jul 29, 2021
@andymina andymina force-pushed the NODE-3405/implement-MongoRuntimeError-children branch 3 times, most recently from 9631286 to 0aa6910 Compare August 10, 2021 14:15
@andymina andymina force-pushed the NODE-3405/implement-MongoRuntimeError-children branch from 4722cc8 to 3264b92 Compare August 10, 2021 20:58
@andymina andymina requested a review from dariakp August 10, 2021 21:17
import type { GridFSBucket } from './index';
import type { GridFSFile } from './download';
import type { WriteConcernOptions } from '../write_concern';
import type { Collection } from '../collection';
Copy link
Contributor

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

drainWaitQueue(
topology[kWaitQueue],
new MongoDriverError('Topology is closed, please connect')
new MongoTopologyClosedError(`${TOPOLOGY_CLOSED_ERROR}, please connect`)
Copy link
Contributor

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') {
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@andymina andymina requested a review from nbbeeken August 10, 2021 22:11
@nbbeeken nbbeeken requested a review from emadum August 11, 2021 14:46
}
if (!waitQueueMember[kCancelled]) {
waitQueueMember.callback(new MongoDriverError('connection pool closed'));
waitQueueMember.callback(new MongoAPIError('Connection pool closed'));
Copy link
Contributor

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

Copy link
Contributor

@emadum emadum left a 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') {
Copy link
Contributor

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.

// Did the user destroy the topology
if (getTopology(db).isDestroyed())
return callback(new MongoDriverError('topology was destroyed'));
return callback(new MongoTopologyClosedError('Topology was destroyed'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Contributor

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

@andymina
Copy link
Contributor Author

@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.

@andymina andymina requested a review from dariakp August 11, 2021 17:52
@andymina andymina requested a review from dariakp August 12, 2021 20:53
@W-A-James W-A-James merged commit fb0b27d into 4.1 Aug 12, 2021
@W-A-James W-A-James deleted the NODE-3405/implement-MongoRuntimeError-children branch August 12, 2021 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Team Review Needs review from team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants