Skip to content

Commit

Permalink
Handle errory connection string
Browse files Browse the repository at this point in the history
  • Loading branch information
timoxley committed Feb 8, 2012
1 parent 1f24314 commit 7c20db7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Expand Up @@ -100,6 +100,10 @@ dnode.prototype.connect = function () {
}

function attachDnode() {
if (!stream) {
self.emit('error', new Error('Could not create a stream with this information ' + JSON.stringify(params)))
return null
}
client = createClient(self.proto, stream);

client.end = function () {
Expand Down
12 changes: 12 additions & 0 deletions test/error.js
Expand Up @@ -85,3 +85,15 @@ test('refused', function (t) {
t.end();
});
});


test('bad connection string', function(t) {
try {
var client = dnode.connect('garbage', function (remote, conn) {
assert.fail('should have been refused, very unlikely');
});
} catch (err) {
t.ok(/Could not create a stream/.test(err.message));
t.end();
}
});

0 comments on commit 7c20db7

Please sign in to comment.