Skip to content

Commit

Permalink
index: emit an "error" event when data is written with no parsing fun…
Browse files Browse the repository at this point in the history
…ction is in place
  • Loading branch information
TooTallNate committed Jun 18, 2014
1 parent a8ee41c commit 24c2565
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion index.js
Expand Up @@ -158,7 +158,9 @@ function transform (chunk, output, fn) {
*/

function _data (stream, chunk, output, fn) {
assert(stream._parserBytesLeft > 0, 'got data but not currently parsing anything');
if (stream._parserBytesLeft <= 0) {
return fn(new Error('got data but not currently parsing anything'));
}

if (chunk.length <= stream._parserBytesLeft) {
// small buffer fits within the "_parserBytesLeft" window
Expand Down
11 changes: 10 additions & 1 deletion test/writable.js
Expand Up @@ -143,6 +143,16 @@ describe('Writable streams', function () {
w.end(data);
});

it('should emit an "error" event when data is written with no parsing function', function (done) {
var w = new Writable();
Parser(w);
w.once('error', function (err) {
assert(err);
done();
});
w.write('a');
});

});

describe('FrameParser', function () {
Expand Down Expand Up @@ -177,7 +187,6 @@ describe('Writable streams', function () {
p.write(new Buffer([ s.length ]));
p.write(new Buffer(s));
p.end();

});

it('should emit 2 "frame" events', function (done) {
Expand Down

0 comments on commit 24c2565

Please sign in to comment.