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

Fix error propagation in iterator #60

Merged
merged 2 commits into from
Aug 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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