Skip to content

Commit

Permalink
Add extendsError method
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed May 1, 2015
1 parent 0b78bc0 commit 52b0f3b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### Master Branch

* Support cluster auto reconnection.
* Add `maxRedirections` option to Cluster.
* Remove `roleRetryDelay` option in favor of `sentinelRetryStrategy`.
* Improve compatibility with node_redis.
* More stable sentinel connection.
Expand Down
10 changes: 2 additions & 8 deletions lib/parsers/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var events = require('events');
var util = require('util');
var utils = require('../utils');
var ReplyError = require('../reply_error');

function Packet(type, size) {
Expand All @@ -22,14 +23,7 @@ util.inherits(ReplyParser, events.EventEmitter);

module.exports = ReplyParser;

function IncompleteReadBuffer(message) {
Error.call(this);
Error.captureStackTrace(this, this.constructor);

this.name = this.constructor.name;
this.message = message;
}
util.inherits(IncompleteReadBuffer, Error);
var IncompleteReadBuffer = utils.extendsError('IncompleteReadBuffer');

// Buffer.toString() is quite slow for small strings
function smallToString(buf, start, end) {
Expand Down
15 changes: 2 additions & 13 deletions lib/reply_error.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
'use strict';

var util = require('util');
var utils = require('./utils');

function ReplyError(message) {
Error.call(this);
Error.captureStackTrace(this, this.constructor);

this.name = this.constructor.name;
this.message = message;
}

// inherit from Error
util.inherits(ReplyError, Error);

module.exports = ReplyError;
module.exports = utils.extendsError('ReplyError');
16 changes: 16 additions & 0 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
var urllib = require('url');
var util = require('util');
var _ = require('lodash');

/**
Expand Down Expand Up @@ -282,3 +283,18 @@ exports.parseURL = function (url) {

return result;
};

exports.extendsError = function (name) {
var errorClass = function (message) {
Error.call(this);
Error.captureStackTrace(this, this.constructor);

this.name = name;
this.message = message;
};

// inherit from Error
util.inherits(errorClass, Error);

return errorClass;
};

0 comments on commit 52b0f3b

Please sign in to comment.