diff --git a/index.js b/index.js index f724d56060..6e8be469f4 100644 --- a/index.js +++ b/index.js @@ -152,13 +152,7 @@ RedisClient.prototype.flush_and_error = function (message) { while (this.offline_queue.length > 0) { command_obj = this.offline_queue.shift(); if (typeof command_obj.callback === "function") { - try { - command_obj.callback(error); - } catch (callback_err) { - process.nextTick(function () { - throw callback_err; - }); - } + command_obj.callback(error); } } this.offline_queue = new Queue(); @@ -166,13 +160,7 @@ RedisClient.prototype.flush_and_error = function (message) { while (this.command_queue.length > 0) { command_obj = this.command_queue.shift(); if (typeof command_obj.callback === "function") { - try { - command_obj.callback(error); - } catch (callback_err) { - process.nextTick(function () { - throw callback_err; - }); - } + command_obj.callback(error); } } this.command_queue = new Queue(); @@ -529,38 +517,13 @@ RedisClient.prototype.return_error = function (err) { this.emit("drain"); this.should_buffer = false; } - - try { + if (command_obj.callback) { command_obj.callback(err); - } catch (callback_err) { - // if a callback throws an exception, re-throw it on a new stack so the parser can keep going - process.nextTick(function () { - throw callback_err; - }); + } else { + this.emit('error', err); } }; -// if a callback throws an exception, re-throw it on a new stack so the parser can keep going. -// if a domain is active, emit the error on the domain, which will serve the same function. -// put this try/catch in its own function because V8 doesn't optimize this well yet. -function try_callback(callback, reply) { - try { - callback(null, reply); - } catch (err) { - if (process.domain) { - var currDomain = process.domain; - currDomain.emit('error', err); - if (process.domain === currDomain) { - currDomain.exit(); - } - } else { - process.nextTick(function () { - throw err; - }); - } - } -} - // hgetall converts its replies to an Object. If the reply is empty, null is returned. function reply_to_object(reply) { var obj = {}, j, jl, key, val; @@ -638,7 +601,7 @@ RedisClient.prototype.return_reply = function (reply) { reply = reply_to_object(reply); } - try_callback(command_obj.callback, reply); + command_obj.callback(null, reply); } else { debug("no callback for reply: " + (reply && reply.toString && reply.toString())); } @@ -662,7 +625,7 @@ RedisClient.prototype.return_reply = function (reply) { // reply[1] can be null var reply1String = (reply[1] === null) ? null : reply[1].toString(); if (command_obj && typeof command_obj.callback === "function") { - try_callback(command_obj.callback, reply1String); + command_obj.callback(null, reply1String); } this.emit(type, reply1String, reply[2]); // channel, count } else { diff --git a/test/commands/eval.spec.js b/test/commands/eval.spec.js index abe307275b..b4a1cd0a49 100644 --- a/test/commands/eval.spec.js +++ b/test/commands/eval.spec.js @@ -118,6 +118,14 @@ describe("The 'eval' method", function () { helper.serverVersionAtLeast.call(this, client, [2, 5, 0]); client.evalsha('ffffffffffffffffffffffffffffffffffffffff', 0, helper.isError(done)); }); + + it('emits an error if SHA does not exist and no callback has been provided', function (done) { + client.on('error', function (err) { + assert.equal(err.message, 'NOSCRIPT No matching script. Please use EVAL.'); + done(); + }); + client.evalsha('ffffffffffffffffffffffffffffffffffffffff', 0); + }); }); it('allows a key to be incremented, and performs appropriate conversion from LUA type', function (done) {