Skip to content

Commit

Permalink
Body error trumps finalizer error.
Browse files Browse the repository at this point in the history
  • Loading branch information
flatheadmill committed Dec 14, 2015
1 parent 2e76a25 commit 42a8bd5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
9 changes: 6 additions & 3 deletions cadence.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,15 @@ function invoke (cadence) {

if (fn == null) {
if (cadence.finalizers.length) {
var finalizer = cadence.finalizers.pop(), error = cadence.errors[0]
var finalizer = cadence.finalizers.pop(), errors = cadence.errors
fn = function () {
async(function () {
return finalizer.vargs
}, finalizer.steps[0], function () {
if (error) throw error
}, [finalizer.steps[0], function (error) {
if (errors.length) throw errors[0]
throw error
}], function () {
if (errors.length) throw errors[0]
return vargs
})
}
Expand Down
18 changes: 16 additions & 2 deletions t/cadence/finalizer.t.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require('proof')(6, prove)
require('proof')(8, prove)

function prove (assert) {
var cadence = require('../..')
Expand Down Expand Up @@ -27,10 +27,24 @@ function prove (assert) {
return 1
})
})(function (error) {
assert(error.message, 'one', 'first finalizer error')
assert(error.message, 'two', 'second finalizer error')
assert(cleanup, 2, 'both finalizers called')
})

var cleanup = 0
cadence(function (async) {
async([function () {
cleanup++
throw new Error('finalizer')
}], function () {
throw new Error('body')
return 1
})
})(function (error) {
assert(error.message, 'body', 'body error perpetuated')
assert(cleanup, 1, 'on error finalizer called')
})

var cleanup = 0
cadence(function (async) {
async(function () {
Expand Down

0 comments on commit 42a8bd5

Please sign in to comment.