esdf icon indicating copy to clipboard operation
esdf copied to clipboard

Snapshot generation failure hangs Promise

Open rkaw92 opened this issue 7 years ago • 0 comments

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 of when() is deprecated in favor of then() (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?)

rkaw92 avatar Feb 05 '18 15:02 rkaw92