You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Re-throw callback errors on nextTick
Otherwise an error thrown in a callback would be throw on the parser's stack.
This commit is contained in:
24
index.js
24
index.js
@@ -215,7 +215,11 @@ RedisClient.prototype.on_data = function (data) {
|
|||||||
try {
|
try {
|
||||||
this.reply_parser.execute(data);
|
this.reply_parser.execute(data);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.emit("error", err); // this needs to be a different event from connection error
|
// This is an unexpected parser problem, an exception that came from the parser code itself.
|
||||||
|
// Parser should emit "error" events if it notices things are out of whack.
|
||||||
|
// Callbacks that throw exceptions will land in return_reply(), below.
|
||||||
|
// TODO - it might be nice to have a different "error" event for different types of errors
|
||||||
|
this.emit("error", err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -227,7 +231,14 @@ RedisClient.prototype.return_error = function (err) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (command_obj && typeof command_obj.callback === "function") {
|
if (command_obj && typeof command_obj.callback === "function") {
|
||||||
command_obj.callback(err);
|
try {
|
||||||
|
command_obj.callback(err);
|
||||||
|
} catch (err) {
|
||||||
|
// if a callback throws an exception, re-throw it on a new stack so the parser can keep going
|
||||||
|
process.nextTick(function () {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log("no callback to send error: " + util.inspect(err));
|
console.log("no callback to send error: " + util.inspect(err));
|
||||||
// this will probably not make it anywhere useful, but we might as well throw
|
// this will probably not make it anywhere useful, but we might as well throw
|
||||||
@@ -256,7 +267,14 @@ RedisClient.prototype.return_reply = function (reply) {
|
|||||||
reply = obj;
|
reply = obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
command_obj.callback(null, reply);
|
try {
|
||||||
|
command_obj.callback(null, reply);
|
||||||
|
} catch (err) {
|
||||||
|
// if a callback throws an exception, re-throw it on a new stack so the parser can keep going
|
||||||
|
process.nextTick(function () {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
}
|
||||||
} else if (exports.debug_mode) {
|
} else if (exports.debug_mode) {
|
||||||
console.log("no callback for reply: " + (reply && reply.toString && reply.toString()));
|
console.log("no callback for reply: " + (reply && reply.toString && reply.toString()));
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,10 @@
|
|||||||
/*global Buffer require exports console setTimeout */
|
/*global Buffer require exports console setTimeout */
|
||||||
|
|
||||||
|
// TODO - incorporate these V8 pro tips:
|
||||||
|
// pre-allocate Arrays if length is known in advance
|
||||||
|
// do not use delete
|
||||||
|
// use numbers for parser state
|
||||||
|
|
||||||
var events = require("events"),
|
var events = require("events"),
|
||||||
util = require("../util").util;
|
util = require("../util").util;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user