Uploaded image for project: 'Compass '
  1. Compass
  2. COMPASS-6395

Investigate changes in NODE-4890: Not all errors from BSON extend from BSONError

    • Type: Icon: Investigation Investigation
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • No version
    • Affects Version/s: None
    • Component/s: None
    • 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:
            Unassigned Unassigned
            Reporter:
            dbeng-pm-bot PM Bot
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: