esdf
esdf copied to clipboard
Snapshot generation failure hangs Promise
If generating an EventSourcedAggregate snapshot in #commit() throws an error, the Promise returned from the method never settles. This is because:
- We return a deferred's
.promise - We never fire the resolver (or rejecter)
This can be seen in https://github.com/rkaw92/esdf/blob/v0.2.5/EventSourcedAggregate.js#L412 - _saveSnapshot() is called and if it throws, the whole function (_commitSinkSucceeded) must exit, so it never reaches the resolver. This is different than failing to save the snapshot to storage - that would only reject some (unhandled) promise and not bail out of _commitSinkSucceeded.
For a clean solution, we should:
- Refactor
commit()so that it no longer relies on a deferred - Get rid of
when(promiseOrValue, onFulfilled, onRejected)- unrelated to this issue, but apparently the if/then/else form ofwhen()is deprecated in favor ofthen()(and has been for a while now!) - Catch snapshot errors in a general way (
when.try?) and handle in an uniform manner (log them somewhere?)