-
Type: Bug
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
What problem are you facing?
BSONTypeError and BSONError cannot be checked with instanceof, because the prototype chain is lost when transpiling to lower versions of JS.
What driver and relevant dependency versions are you using?
BSON 4.x
Steps to reproduce?
const b = new BSONTypeError();
b instanceof BSONTypeError;
We should use Object.setPrototypeOf to fix this.
Acceptance Criteria
- Fix the errors to ensure they show up with the correct names in stack trace and respond properly to instanceof checks. Add tests to make sure.
- BSONTypeError should evaluate true for BSONTypeError and TypeError instanceof checks
- Similarly for BSONError
- Update tests that test for throw `TypeError` or `Error` to check for the `BSONTypeError` and `BSONError` instead
- Remove the assertion override for `throw` in register-bson.ts since it should not be necessary (verify that tests pass)