vigetlabs / microcosm

Flux with actions at center stage. Write optimistic updates, cancel requests, and track changes with ease.
http://code.viget.com/microcosm/
MIT License
487 stars 22 forks source link

Handle promise errors using second argument of then() #524

Closed nhunzaker closed 6 years ago

nhunzaker commented 6 years ago

What

This commit changes the way Subjects and Microcosm action resolution handle promises such that the error state is passed into the second argument of promise.then().

This prevents a case where callbacks following the success case could raise an exception, but it would be trapped by the .catch() API call. So errors would "disappear" in the following case:

const repo = new Microcosm()

repo.addDomain('test', {
  register() {
    return {
      action: () => {
        throw 'Oops'
      }
    }
  }
})

await repo.push('action') // => where did the error go?
codecov-io commented 6 years ago

Codecov Report

Merging #524 into master will increase coverage by 0.25%. The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #524      +/-   ##
==========================================
+ Coverage   93.88%   94.13%   +0.25%     
==========================================
  Files          32       32              
  Lines         801      802       +1     
  Branches      162      162              
==========================================
+ Hits          752      755       +3     
+ Misses         42       40       -2     
  Partials        7        7
Impacted Files Coverage Δ
packages/microcosm/src/scheduler.js 95.34% <0%> (+4.43%) :arrow_up:
packages/microcosm/src/coroutine.js 100% <100%> (ø) :arrow_up:
packages/microcosm/src/subject.js 100% <100%> (ø) :arrow_up:
packages/microcosm/src/observable.js 89.16% <93.33%> (+0.18%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update ed603ac...f645efc. Read the comment docs.

nhunzaker commented 6 years ago

Thanks, @dce !