-
Notifications
You must be signed in to change notification settings - Fork 1.8k
refactor(NODE-3402): Implement MongoAPIError and its children #2883
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
I can't leave comments on things you didn't change so unfortunately this will have to do for now ;(
|
|
|
|
|
|
|
@@ -355,7 +361,7 @@ export class ChangeStream<TSchema extends Document> extends TypedEventEmitter<Ch | |||
*/ | |||
stream(options?: CursorStreamOptions): Readable { | |||
this.streamOptions = options; | |||
if (!this.cursor) throw new MongoDriverError(NO_CURSOR_ERROR); | |||
if (!this.cursor) throw new MongoInvalidArgumentError(NO_CURSOR_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.
I'm not sure if this should be under MongoInvalidArgumentError
since the user isn't providing the cursor in this function, nor in the constructor. I feel like it might fall under MongoChangeStreamError
which is covered in NODE-3404.
src/error.ts
Outdated
export class MongoAPIError extends MongoDriverError { | ||
constructor(message: string) { | ||
super(message); | ||
this.name = 'MongoAPIError'; |
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.
NODE-3368 just got merged which made the name prop of error classes getter functions. Moving forward names should implemented as:
get name(): string {
return 'MongoAPIError';
}
Can you add these changes so we can stay consistent?
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.
Will do
@@ -248,7 +254,7 @@ export function executeLegacyOperation( | |||
const optionsIndex = args.length - 2; | |||
args[optionsIndex] = Object.assign({}, args[optionsIndex], { session: session }); | |||
} else if (opOptions.session && opOptions.session.hasEnded) { | |||
throw new MongoDriverError('Use of expired sessions is not permitted'); | |||
throw new MongoInvalidArgumentError('Use of expired sessions is not permitted'); |
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 torn about this one. The same error message appears in src/operations/execute_operation.ts:88
as well so I feel like the verdict has to be consistent for the two cases. That being said I'm not sure whether MongoInvalidArgumentError
or MongoResourceClosedError
would fit better here. Definitely open to other perspectives.
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 had left the error in src/operations/execute_operation.ts:88
because of that ambiguity. Was intending to leave that until we added the MongoResourceClosedError
and its children, so yeah, I think you're right about changing this to MongoResourceClosedError
as well
…n of MongoAPIError
98fbf25
to
34389d1
Compare
Closing for replacement with #2891 |
Description
Implement the errors detailed in docs/errors.md from NODE-3363 that fall under MongoAPIError
What changed?
Replaced some MongoDriverError instances with the following errors where appropriate