From 3b07ee587c15ee1fcff963f9d32818b44c9f407b Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Sat, 1 Nov 2014 19:01:25 +0100 Subject: [PATCH] Handle parsing error over streams. --- lib/parseStream.js | 1 + test.js | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/parseStream.js b/lib/parseStream.js index e499a39..c681cb5 100644 --- a/lib/parseStream.js +++ b/lib/parseStream.js @@ -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) diff --git a/test.js b/test.js index 294b025..6cf39d4 100644 --- a/test.js +++ b/test.js @@ -97,7 +97,6 @@ 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') @@ -105,6 +104,18 @@ function testParseError(expected, fixture) { 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) {