Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #60 from s1na/patch-1
Browse files Browse the repository at this point in the history
Fix error propagation in iterator
  • Loading branch information
holgerd77 committed Aug 8, 2018
2 parents 3752761 + fcc98b1 commit 96b4f36
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ Blockchain.prototype._iterator = function (name, func, cb) {
async.whilst(
() => blockNumber,
run,
() => self._saveHeads(cb)
(err) => err ? cb(err) : self._saveHeads(cb)
)
})

Expand Down
11 changes: 10 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const testData = require('./testdata.json')
const BN = require('bn.js')

test('blockchain test', function (t) {
t.plan(59)
t.plan(61)
var blockchain = new Blockchain()
var genesisBlock
var blocks = []
Expand Down Expand Up @@ -220,6 +220,15 @@ test('blockchain test', function (t) {
done()
})
},
function iterateError (done) {
blockchain.iterator('error', function (block, reorg, cb) {
cb(new Error('iterator func error'))
}, function (err) {
t.ok(err, 'should catch iterator func error')
t.equal(err.message, 'iterator func error', 'should return correct error')
done()
})
},
function iterateEmpty (done) {
var blockchain = new Blockchain()
blockchain.validate = false
Expand Down

0 comments on commit 96b4f36

Please sign in to comment.