forked from redis/node-redis
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request redis#139 from felixge/master
Fix: Hiredis parser traps pubsub event exceptions
- Loading branch information
Showing
2 changed files
with
52 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
var Parser = require('../lib/parser/hiredis').Parser; | ||
var assert = require('assert'); | ||
|
||
/* | ||
This test makes sure that exceptions thrown inside of "reply" event handlers | ||
are not trapped and mistakenly emitted as parse errors. | ||
*/ | ||
(function testExecuteDoesNotCatchReplyCallbackExceptions() { | ||
var parser = new Parser(); | ||
var replies = [{}]; | ||
|
||
parser.reader = { | ||
feed: function() {}, | ||
get: function() { | ||
return replies.shift(); | ||
} | ||
}; | ||
|
||
var emittedError = false; | ||
var caughtException = false; | ||
|
||
parser | ||
.on('error', function() { | ||
emittedError = true; | ||
}) | ||
.on('reply', function() { | ||
throw new Error('bad'); | ||
}); | ||
|
||
try { | ||
parser.execute(); | ||
} catch (err) { | ||
caughtException = true; | ||
} | ||
|
||
assert.equal(caughtException, true); | ||
assert.equal(emittedError, false); | ||
})(); |