Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-3724

BSONTypeError and BSONError do not respect instanceof checks

    • Not Needed

      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;

      https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work

      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) 

            Assignee:
            grace.chong@mongodb.com Grace Chong (Inactive)
            Reporter:
            neal.beeken@mongodb.com Neal Beeken
            Daria Pardue
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: