Skip to content

Commit

Permalink
Handle parsing error over streams.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Nov 1, 2014
1 parent 60bd4d0 commit 3b07ee5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/parseStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function parseStream(opts) {
, stream = through.obj(process)

parser.on('packet', push)
parser.on('error', stream.emit.bind(stream, 'error'))

function process(chunk, enc, cb) {
parser.parse(chunk)
Expand Down
13 changes: 12 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,25 @@ function testParseError(expected, fixture) {
t.plan(1)

var parser = mqtt.parser()
, rest

parser.on('error', function(err) {
t.equal(err.message, expected, 'expected error message')
})

parser.parse(fixture)
})

test(expected + ' over parseStream', function(t) {
t.plan(1)

var parser = mqtt.parseStream()

parser.on('error', function(err) {
t.equal(err.message, expected, 'expected error message')
})

parser.end(fixture)
})
}

function testGenerateError(expected, fixture) {
Expand Down

0 comments on commit 3b07ee5

Please sign in to comment.