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

  • MongoURIError
  • MongoStreamError
  • MongoChangeStreamError
  • MongoGridFSStreamError
  • MongoGridFSChunkError
  • MongoCompressionError
  • MongoDecompressionError

@andymina andymina added the wip label Jul 16, 2021
@andymina andymina force-pushed the NODE-3404/Implement-MongoRuntimeError-children branch 2 times, most recently from 1bfa5fc to 990c92c Compare July 19, 2021 17:30
@andymina andymina self-assigned this Jul 19, 2021
@andymina andymina requested a review from W-A-James July 20, 2021 17:46
@andymina andymina marked this pull request as ready for review July 20, 2021 17:46
@andymina andymina removed the wip label Jul 20, 2021
@W-A-James
Copy link
Contributor

Apart from requested changes, LGTM

@W-A-James W-A-James added the Team Review Needs review from team label Jul 20, 2021
@W-A-James W-A-James requested review from dariakp, emadum and nbbeeken July 20, 2021 21:33
@W-A-James W-A-James added Primary Review In Review with primary reviewer, not yet ready for team's eyes and removed Team Review Needs review from team labels Jul 21, 2021
@andymina andymina requested a review from W-A-James July 21, 2021 18:38
@andymina andymina force-pushed the NODE-3404/Implement-MongoRuntimeError-children branch from bc6fe74 to 0e77b80 Compare July 26, 2021 19:38
@W-A-James W-A-James removed the request for review from emadum July 26, 2021 20:04
@andymina andymina requested a review from W-A-James July 26, 2021 20:20
@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
if (compressorID < 0 || compressorID > Math.max(2)) {
throw new MongoDriverError(
throw new MongoDecompressionError(
`Server sent message compressed using an unsupported compressor.` +
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets make this one template string?

callback(
new MongoDriverError(
new MongoDecompressionError(
'Decompressing a compressed message from the server failed. The message is corrupt.'
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like we could improve the message a bit here, a MongoDecompressError implies the first sentence maybe its worth being specific, we can workshop but something like: 'Message header size does not match message body size'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How does 'Message body and message header must be the same length' sound?

expectedLength;
return __handleError(stream, new MongoDriverError(errmsg));
errmsg = `ChunkIsWrongSize: Got unexpected length: ${buf.byteLength}, expected: ${expectedLength}`;
return __handleError(stream, new MongoGridFSChunkError(errmsg));
Copy link
Contributor

Choose a reason for hiding this comment

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

__handleError is a oneliner (maybe it contained more at some point) can we just inline it everywhere?

      return stream.emit(
        GridFSBucketReadStream.ERROR,
        new MongoGridFSChunkError(
          `ChunkIsWrongSize: Got unexpected length: ${buf.byteLength}, expected: ${expectedLength}`
        )
      );

abort(callback?: Callback<void>): Promise<void> | void {
const Promise = PromiseProvider.get();
let error: MongoDriverError;
let error: MongoGridFSStreamError;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we refactor this to use maybePromise?

Copy link
Contributor Author

@andymina andymina Jul 27, 2021

Choose a reason for hiding this comment

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

In hindsight, I think this whole thing is out of scope for this ticket. I think MongoStreamClosedError, covered in NODE-3405, better covers the errors thrown here. I'll leave a TODO comment for that PR and revert this change.

MongoGridFSChunkError,
MongoGridFSStreamError
} from '../error';
import type { FindOptions } from '../operations/find';
Copy link
Contributor

Choose a reason for hiding this comment

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

There's import changes here that aren't needed, I think you import sorting turned on in vscode? This is something we want to do as a lint fix down the line if you don't mind reverting these.

@@ -1,14 +1,20 @@
import type { ObjectId } from 'bson';
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be '../bson' must've slipped through I'll look into linting for this.

@andymina andymina requested review from dariakp and nbbeeken July 27, 2021 20:46
@andymina andymina requested a review from nbbeeken August 6, 2021 15:00
for (const compVal of values as string[]) {
for (const c of compVal.split(',')) {
if (['none', 'snappy', 'zlib'].includes(String(c))) {
if (Object.values(VALID_COMPRESSION_MECHS).includes(String(c))) {
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
if (Object.values(VALID_COMPRESSION_MECHS).includes(String(c))) {
if (Object.keys(Compressor).includes(String(c))) {

We already have an enum Compressor lets use that here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, didn't realize there was an existing enum already 😅

} else {
throw new MongoInvalidArgumentError(
`${c} is not a valid compression mechanism. Must be 'none', 'snappy', or 'zlib'. `
`${c} is not a valid compression mechanism. Must be one of: ${enumToString(
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess that would just make this ${Object.keys(Compressor)}

@andymina andymina requested a review from nbbeeken August 6, 2021 19:09
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.

Other than this small but important detail, LGTM

changeStream.close(close);
} else if (counter >= 3) {
close(new Error('should not have received more than 2 events'));
expect.fail('Should not have received more than 2 events');
Copy link
Contributor

Choose a reason for hiding this comment

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

The original close function here served an important purpose: to prevent done from being called more than once; an expect.fail would throw an error, which would call done in whatever context is currently running, potentially causing unrelated tests to fail. tl;dr: passing the error explicitly to a wrapped done function (the close function in this context), the way it was written originally, is the safest way to handle event listener errors in tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh, I didn't realize that. This was helpful in understanding the tests a bit better. Thank you!

Copy link
Contributor

@nbbeeken nbbeeken left a comment

Choose a reason for hiding this comment

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

once the fix daria mentions is in then this LGTM

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.

LGTM 🎉

@andymina andymina force-pushed the NODE-3404/Implement-MongoRuntimeError-children branch from d2f57e8 to 5659654 Compare August 10, 2021 18:57
@W-A-James W-A-James merged commit e69d992 into 4.1 Aug 10, 2021
@W-A-James W-A-James deleted the NODE-3404/Implement-MongoRuntimeError-children branch August 10, 2021 20:27
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.

4 participants