Skip to content

Commit db6cf0a

Browse files
author
Ruben Bridgewater
committed
Don't throw on invalid data types but throw a warning instead
Fixes #1013
1 parent ddbb94b commit db6cf0a

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,14 +805,21 @@ RedisClient.prototype.send_command = function (command, args, callback) {
805805
'Please handle this in your code to make sure everything works as you intended it to.'
806806
);
807807
args_copy[i] = 'null'; // Backwards compatible :/
808-
} else {
808+
} else if (Buffer.isBuffer(args[i])) {
809809
args_copy[i] = args[i];
810810
command_obj.buffer_args = true;
811811
big_data = true;
812812
if (this.pipeline !== 0) {
813813
this.pipeline += 2;
814814
this.writeDefault = this.writeBuffers;
815815
}
816+
} else {
817+
this.warn(
818+
'Deprecated: The ' + command.toUpperCase() + ' command contains a argument of type ' + args[i].constructor.name + '.\n' +
819+
'This is converted to "' + args[i].toString() + '" by using .toString() now and will return an error from v.3.0 on.\n' +
820+
'Please handle this in your code to make sure everything works as you intended it to.'
821+
);
822+
args_copy[i] = args[i].toString(); // Backwards compatible :/
816823
}
817824
} else if (typeof args[i] === 'undefined') {
818825
this.warn(

test/commands/hset.spec.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,22 @@ describe("The 'hset' method", function () {
4545
});
4646
});
4747

48-
it('throws a error if someone passed a array either as field or as value', function (done) {
48+
it('warns if someone passed a array either as field or as value', function (done) {
4949
var hash = "test hash";
5050
var field = "array";
5151
// This would be converted to "array contents" but if you use more than one entry,
5252
// it'll result in e.g. "array contents,second content" and this is not supported and considered harmful
5353
var value = ["array contents"];
54-
try {
55-
client.HMSET(hash, field, value);
56-
throw new Error('test failed');
57-
} catch (err) {
58-
if (/invalid data/.test(err.message)) {
59-
done();
60-
} else {
61-
done(err);
62-
}
63-
}
54+
client.on('warning', function (msg) {
55+
assert.strictEqual(
56+
msg,
57+
'Deprecated: The HMSET command contains a argument of type Array.\n' +
58+
'This is converted to "array contents" by using .toString() now and will return an error from v.3.0 on.\n' +
59+
'Please handle this in your code to make sure everything works as you intended it to.'
60+
);
61+
done();
62+
});
63+
client.HMSET(hash, field, value);
6464
});
6565

6666
it('does not error when a buffer and date are set as values on the same hash', function (done) {

0 commit comments

Comments
 (0)