[COMPASS-6395] Investigate changes in NODE-4890: Not all errors from BSON extend from BSONError Created: 22/Dec/22  Updated: 12/Jan/23  Resolved: 12/Jan/23

Status: Closed
Project: Compass
Component/s: None
Affects Version/s: None
Fix Version/s: No version

Type: Investigation Priority: Major - P3
Reporter: PM Bot Assignee: Unassigned
Resolution: Done Votes: 0
Labels: node-driver
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on NODE-4890 Not all errors from BSON extend from ... Closed
Documentation Changes: Not Needed

 Description   

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'


 Comments   
Comment by Anna Henningsen [ 12/Jan/23 ]

Nothing to do here for devtools.

Generated at Wed Feb 07 22:42:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.