You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Use built-in error classes to make errors more specific
This commit is contained in:
@@ -12,7 +12,7 @@ module.exports = function createClient (port_arg, host_arg, options) {
|
|||||||
host = host_arg;
|
host = host_arg;
|
||||||
} else {
|
} else {
|
||||||
if (options && host_arg) {
|
if (options && host_arg) {
|
||||||
throw new Error('Unknown type of connection in createClient()');
|
throw new TypeError('Unknown type of connection in createClient()');
|
||||||
}
|
}
|
||||||
options = options || host_arg;
|
options = options || host_arg;
|
||||||
}
|
}
|
||||||
@@ -50,14 +50,14 @@ module.exports = function createClient (port_arg, host_arg, options) {
|
|||||||
if (options[elem] === parsed.query[elem]) {
|
if (options[elem] === parsed.query[elem]) {
|
||||||
console.warn('node_redis: WARNING: You passed the ' + elem + ' option twice!');
|
console.warn('node_redis: WARNING: You passed the ' + elem + ' option twice!');
|
||||||
} else {
|
} else {
|
||||||
throw new Error('The ' + elem + ' option is added twice and does not match');
|
throw new RangeError('The ' + elem + ' option is added twice and does not match');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
options[elem] = parsed.query[elem];
|
options[elem] = parsed.query[elem];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (parsed.hostname) {
|
} else if (parsed.hostname) {
|
||||||
throw new Error('The redis url must begin with slashes "//" or contain slashes after the redis protocol');
|
throw new RangeError('The redis url must begin with slashes "//" or contain slashes after the redis protocol');
|
||||||
} else {
|
} else {
|
||||||
options.path = port_arg;
|
options.path = port_arg;
|
||||||
}
|
}
|
||||||
@@ -67,12 +67,12 @@ module.exports = function createClient (port_arg, host_arg, options) {
|
|||||||
options.host = options.host || host_arg;
|
options.host = options.host || host_arg;
|
||||||
|
|
||||||
if (port_arg && arguments.length !== 1) {
|
if (port_arg && arguments.length !== 1) {
|
||||||
throw new Error('To many arguments passed to createClient. Please only pass the options object');
|
throw new TypeError('To many arguments passed to createClient. Please only pass the options object');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options) {
|
if (!options) {
|
||||||
throw new Error('Unknown type of connection in createClient()');
|
throw new TypeError('Unknown type of connection in createClient()');
|
||||||
}
|
}
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
|
@@ -13,7 +13,7 @@ All documented and exposed API belongs in here
|
|||||||
RedisClient.prototype.send_command = RedisClient.prototype.sendCommand = function (command, args, callback) {
|
RedisClient.prototype.send_command = RedisClient.prototype.sendCommand = function (command, args, callback) {
|
||||||
// Throw to fail early instead of relying in order in this case
|
// Throw to fail early instead of relying in order in this case
|
||||||
if (typeof command !== 'string') {
|
if (typeof command !== 'string') {
|
||||||
throw new Error('Wrong input type "' + (command !== null && command !== undefined ? command.constructor.name : command) + '" for command name');
|
throw new TypeError('Wrong input type "' + (command !== null && command !== undefined ? command.constructor.name : command) + '" for command name');
|
||||||
}
|
}
|
||||||
if (!Array.isArray(args)) {
|
if (!Array.isArray(args)) {
|
||||||
if (args === undefined || args === null) {
|
if (args === undefined || args === null) {
|
||||||
@@ -22,11 +22,11 @@ RedisClient.prototype.send_command = RedisClient.prototype.sendCommand = functio
|
|||||||
callback = args;
|
callback = args;
|
||||||
args = [];
|
args = [];
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Wrong input type "' + args.constructor.name + '" for args');
|
throw new TypeError('Wrong input type "' + args.constructor.name + '" for args');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (typeof callback !== 'function' && callback !== undefined) {
|
if (typeof callback !== 'function' && callback !== undefined) {
|
||||||
throw new Error('Wrong input type "' + (callback !== null ? callback.constructor.name : 'null') + '" for callback function');
|
throw new TypeError('Wrong input type "' + (callback !== null ? callback.constructor.name : 'null') + '" for callback function');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Using the raw multi command is only possible with this function
|
// Using the raw multi command is only possible with this function
|
||||||
|
@@ -46,7 +46,6 @@ function multi_callback (self, err, replies) {
|
|||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
err.errors = self.errors;
|
err.errors = self.errors;
|
||||||
err.command = 'EXEC';
|
|
||||||
if (self.callback) {
|
if (self.callback) {
|
||||||
self.callback(err);
|
self.callback(err);
|
||||||
// Exclude connection errors so that those errors won't be emitted twice
|
// Exclude connection errors so that those errors won't be emitted twice
|
||||||
@@ -86,7 +85,7 @@ function multi_callback (self, err, replies) {
|
|||||||
|
|
||||||
Multi.prototype.exec_transaction = function exec_transaction (callback) {
|
Multi.prototype.exec_transaction = function exec_transaction (callback) {
|
||||||
if (this.monitoring || this._client.monitoring) {
|
if (this.monitoring || this._client.monitoring) {
|
||||||
var err = new Error(
|
var err = new RangeError(
|
||||||
'Using transaction with a client that is in monitor mode does not work due to faulty return values of Redis.'
|
'Using transaction with a client that is in monitor mode does not work due to faulty return values of Redis.'
|
||||||
);
|
);
|
||||||
err.command = 'EXEC';
|
err.command = 'EXEC';
|
||||||
|
Reference in New Issue
Block a user