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

Not all errors from BSON extend from BSONError

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • bson-5.0.0
    • Affects Version/s: bson-4.7.0, bson-5.0.0
    • Component/s: BSON
    • 3
    • Needed
    • Not Needed

      What problem are you facing?

      Some of the errors were missed when we created a new BSONError class here. See long.ts and serializer.ts

      In addition, in order to not break inheritance a new BSONTypeError was created to inherit from TypeError. However, this creates a disconnect where some errors are instanceof BSONError and some are instanceof BSONTypeError.

      What driver and relevant dependency versions are you using?

      BSON v4 and soon v5

      What is the improvement you would like?

      • Remove BSONTypeError, it would be confusing to keep it and have it subclass from BSONError
      • Either:
        • Do not add any subclasses to BSONError now or ever, instanceof is finicky in web environments, users that face cross realm issues would prefer to check error.name
        • Or consider adding a BSONError.isBSONError(error) à la Array.isArray to support filtering in places where instanceof does not work

      Follow up if no subclasses

      • If an improvement to error subject area is desired consider an enum of strings prepended to the message: (subject or code)
      • new BSONError('cannot put null in keys', { subject: 'serializer' })
        • Uncaught: BSONError: [serializer] cannot put null in keys
        • error.subject === 'serializer'

            Assignee:
            neal.beeken@mongodb.com Neal Beeken
            Reporter:
            neal.beeken@mongodb.com Neal Beeken
            Durran Jordan
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: