Permalink
Browse files

Emit catchable error events instead of throwing an exception when mal…

…formed frames come in
  • Loading branch information...
sorear committed Dec 5, 2012
1 parent bf1ea47 commit 4394f005260f6f8026ac7fe7eb2372fcce489e13
Showing with 14 additions and 2 deletions.
  1. +14 −2 lib/client.js
View
@@ -78,8 +78,20 @@ function BinaryClient(socket, options) {
data = data.data;
-
- data = util.unpack(data);
+ try {
+ data = util.unpack(data);
+ } catch (ex) {
+ return self.emit('error', 'Received unparsable message: ' + ex);
+ }
+ if (!(data instanceof Array))
+ return self.emit('error', 'Received non-array message');
+ if (data.length != 3)
+ return self.emit('error', 'Received message with wrong part count: ' + data.length);
+ if ('number' != typeof data[0])
+ return self.emit('error', 'Received message with non-number type: ' + data[0]);
+ if ('number' != typeof data[2])
+ return self.emit('error', 'Received message with non-number streamId: ' + data[2]);
+
switch(data[0]) {
case 0:
// Reserved

0 comments on commit 4394f00

Please sign in to comment.