Skip to content

Commit a2255d7

Browse files
author
Ruben Bridgewater
committed
Fix error messages not being visible in the stack trace of AbortErrors
1 parent e4ce21e commit a2255d7

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,8 @@ exports.RedisClient = RedisClient;
10871087
exports.print = utils.print;
10881088
exports.Multi = require('./lib/multi');
10891089
exports.AbortError = errorClasses.AbortError;
1090+
exports.RedisError = Parser.RedisError;
1091+
exports.ParserError = Parser.ParserError;
10901092
exports.ReplyError = Parser.ReplyError;
10911093
exports.AggregateError = errorClasses.AggregateError;
10921094

lib/customErrors.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,55 @@
11
'use strict';
22

33
var util = require('util');
4+
var assert = require('assert')
5+
var RedisError = require('redis-parser').RedisError
6+
var ADD_STACKTRACE = false
47

5-
function AbortError (obj) {
6-
Error.captureStackTrace(this, this.constructor);
8+
function AbortError (obj, stack) {
9+
assert(obj, 'The options argument is required')
10+
assert.strictEqual(typeof obj, 'object', 'The options argument has to be of type object')
11+
12+
RedisError.call(this, obj.message, ADD_STACKTRACE)
713
Object.defineProperty(this, 'message', {
814
value: obj.message || '',
915
configurable: true,
1016
writable: true
1117
});
18+
if (stack || stack === undefined) {
19+
Error.captureStackTrace(this, AbortError)
20+
}
1221
for (var keys = Object.keys(obj), key = keys.pop(); key; key = keys.pop()) {
1322
this[key] = obj[key];
1423
}
1524
}
1625

1726
function AggregateError (obj) {
18-
Error.captureStackTrace(this, this.constructor);
27+
assert(obj, 'The options argument is required')
28+
assert.strictEqual(typeof obj, 'object', 'The options argument has to be of type object')
29+
30+
AbortError.call(this, obj, ADD_STACKTRACE)
1931
Object.defineProperty(this, 'message', {
2032
value: obj.message || '',
2133
configurable: true,
2234
writable: true
2335
});
36+
Error.captureStackTrace(this, AggregateError);
2437
for (var keys = Object.keys(obj), key = keys.pop(); key; key = keys.pop()) {
2538
this[key] = obj[key];
2639
}
2740
}
2841

29-
util.inherits(AbortError, Error);
42+
util.inherits(AbortError, RedisError);
3043
util.inherits(AggregateError, AbortError);
3144

3245
Object.defineProperty(AbortError.prototype, 'name', {
3346
value: 'AbortError',
34-
// configurable: true,
47+
configurable: true,
3548
writable: true
3649
});
3750
Object.defineProperty(AggregateError.prototype, 'name', {
3851
value: 'AggregateError',
39-
// configurable: true,
52+
configurable: true,
4053
writable: true
4154
});
4255

test/node_redis.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ describe('The node_redis client', function () {
870870
client.on('error', function (err) {
871871
assert.strictEqual(err.message, 'Protocol error, got "a" as reply type byte. Please report this.');
872872
assert.strictEqual(err, error);
873-
assert(err instanceof redis.ReplyError);
873+
assert(err instanceof redis.ParserError);
874874
// After the hard failure work properly again. The set should have been processed properly too
875875
client.get('foo', function (err, res) {
876876
assert.strictEqual(res, 'bar');

0 commit comments

Comments
 (0)