Skip to content
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

feat(NODE-4890)!: make all thrown errors into BSONErrors #545

Merged
merged 2 commits into from
Dec 22, 2022

Conversation

nbbeeken
Copy link
Contributor

@nbbeeken nbbeeken commented Dec 22, 2022

Description

What is changing?

Unlike the driver our BSON error classes diverged making filtering for BSONTypeError vs BSONError misaligned with our error expectations. We now have one error class, which we can make future subclasses of, and it offers a method isBSONError that will return true for the current class or any future subclass regardless of cross environment instantiation.

What is the motivation for this change?

A BSONError can be thrown from deep within a library that relies on BSON, having one error super class for the library helps with programmatic filtering of an error's origin.

Hypothetical example: A collection in our Db has an issue with UTF-8 data

let documentCount = 0;
const cursor = collection.find({}, { utf8Validation: true });
try {
  for await (const doc of cursor) documentCount += 1;
} catch (error) {
  if (BSONError.isBSONError(error)) {
    console.log(`Found the troublemaker UTF-8!: ${documentCount} ${error.message}`);
    return documentCount;
  }
  throw error;
}

Double check the following

  • Ran npm run lint script
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • TODO Update migration guide

@nbbeeken nbbeeken marked this pull request as ready for review December 22, 2022 17:55
@durran durran added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Dec 22, 2022
@durran durran merged commit 5b837a9 into main Dec 22, 2022
@durran durran deleted the NODE-4890-fix-error-throw branch December 22, 2022 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Primary Review In Review with primary reviewer, not yet ready for team's eyes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants