composablesys / collabs

Collabs library monorepo
https://collabs.readthedocs.io/
Apache License 2.0
254 stars 11 forks source link

Handle errors in event emitters #257

Open mweidner037 opened 1 year ago

mweidner037 commented 1 year ago

Currently, EventEmitter traps any errors emitted by an event handler, merely logging them to console.error. We should consider letting these errors just propagate normally. That way, errors caused by local ops (including parent CRDT logic in an event listener) propagate immediately and prevent a message from being sent, and mocha can see these errors during tests.

My concern is that an error in an "irrelevant" event handler will then interfere with the other handlers and the event emitter. But perhaps this is not really an issue, especially since events are often handled at most once (either by the parent CRDT or by the GUI component rendering the CRDT). And you can always "opt out" using a top level try-catch in your own event handlers.

mweidner037 commented 1 year ago

Can also clarify related error messages. E.g. "did you try to perform an operation in an event handler?": could also be from a message in a Collab constructor or valueConstructor callback.

It would also be nice to throw an error if you send a message during a registerCollab callback.

mweidner037 commented 1 year ago

Including CRuntime events