Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: shutterstock/node-common-errors
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9f658d5685078749e85852f1b9c0499c3786ec4c
Choose a base ref
...
head repository: shutterstock/node-common-errors
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: bb6c2face856d5d83ac257cb5fd78a0d67fe782e
Choose a head ref
  • 20 commits
  • 27 files changed
  • 4 contributors

Commits on May 19, 2015

  1. add a bunch of new errors

    dfenster committed May 19, 2015
    Copy the full SHA
    26fd4c5 View commit details
  2. Update README.md

    dfenster committed May 19, 2015

    Verified

    This commit was signed with the committer’s verified signature.
    targos Michaël Zasso
    Copy the full SHA
    13d531e View commit details
  3. Update README.md

    dfenster committed May 19, 2015
    Copy the full SHA
    d369e02 View commit details
  4. Update README.md

    dfenster committed May 19, 2015
    Copy the full SHA
    2e2e0f9 View commit details
  5. increase version number

    dfenster committed May 19, 2015
    Copy the full SHA
    65b3f61 View commit details

Commits on May 31, 2015

  1. fixed DataError usage examples

    rpnzl committed May 31, 2015
    Copy the full SHA
    d4139c5 View commit details

Commits on Jun 2, 2015

  1. Merge pull request #13 from rpnzl/master

    fixed `DataError` usage examples
    dfenster committed Jun 2, 2015
    Copy the full SHA
    77e3554 View commit details

Commits on Oct 9, 2015

  1. Copy the full SHA
    f68bbca View commit details
  2. Copy the full SHA
    fbc99c0 View commit details
  3. Copy the full SHA
    01e294a View commit details
  4. increase version number

    dfenster committed Oct 9, 2015
    Copy the full SHA
    8b13cb6 View commit details
  5. Copy the full SHA
    41fd135 View commit details
  6. Update README.md

    dfenster committed Oct 9, 2015
    Copy the full SHA
    da9e44e View commit details

Commits on May 26, 2016

  1. Copy the full SHA
    4fa2461 View commit details
  2. no longer depend on lodash

    dfenster committed May 26, 2016
    Copy the full SHA
    73059c8 View commit details
  3. test bluebird try/catch

    dfenster committed May 26, 2016
    Copy the full SHA
    106e405 View commit details
  4. Copy the full SHA
    376f551 View commit details

Commits on Jun 7, 2016

  1. Copy the full SHA
    ec8e96b View commit details
  2. Merge pull request #22 from shmuga/move-bluebird-in-deps

    #21. Moved bluebird to devDeps.
    dfenster committed Jun 7, 2016
    Copy the full SHA
    0d1aaf7 View commit details
  3. moved bluebird to devdeps

    dfenster committed Jun 7, 2016
    Copy the full SHA
    bb6c2fa View commit details
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: node_js
node_js:
- "0.8"
- "0.10"
- "0.12"
- "4.1"
221 changes: 221 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -21,14 +21,24 @@ Common error classes and utility functions
* [ArgumentError](#argument)
* [ArgumentNullError](#argumentnull)
* [AuthenticationRequiredError](#authrequired)
* [ConnectionError](#connection)
* [DataError](#data)
* [MemcacedError](#memcached)
* [MongoDBError](#mongodb)
* [RedisError](#redis)
* [RollbackError](#rollback)
* [SQLError](#sql)
* [TransactionError](#transaction)
* [Error](#error)
* [HttpStatusError](#httpstatus)
* [InvalidOperationError](#invalidoperation)
* [IOError](#io)
* [DirectoryNotFoundError](#directorynotfound)
* [DriveNotFoundError](#drivenotfound)
* [EndOfStreamError](#endofstream)
* [FileLoadError](#fileload)
* [FileNotFoundError](#filenotfound)
* [SocketError](#socket)
* [NotFoundError](#notfound)
* [NotImplementedError](#notimplemented)
* [NotPermittedError](#notpermitted)
@@ -38,6 +48,7 @@ Common error classes and utility functions
* [ReferenceError](#reference)
* [StackOverflowError](#stackoverflow)
* [SyntaxError](#syntax)
* [TimeoutError](#timeout)
* [TypeError](#type)
* [URIError](#uri)
* [ValidationError](#validation)
@@ -132,6 +143,158 @@ throw new errors.AuthenticationRequiredError("Please provide authentication.", e

---------------------------------------

<a name="connection" />
### ConnectionError

Applicable when an error occurs on a connection.

new ConnectionError(message[, inner_error])

__Arguments__

* `message` - any message
* `inner_error` - the Error instance that caused the current error. Stack trace will be appended.

```js
// Example
throw new errors.ConnectionError('database connection no longer available', err);
```

---------------------------------------

<a name="data" />
### DataError

Applicable when an error occurs on or with an external data source.

new DataError(message[, inner_error])

__Arguments__

* `message` - any message
* `inner_error` - the Error instance that caused the current error. Stack trace will be appended.

```js
// Example
throw new errors.data.DataError('Too many rows returned from database', err);
```

---------------------------------------

<a name="memcached" />
### MemcachedError

Applicable when an error occurs while using memcached.

new MemcachedError(message[, inner_error])

__Arguments__

* `message` - any message
* `inner_error` - the Error instance that caused the current error. Stack trace will be appended.

```js
// Example
throw new errors.data.MemcachedError('Expected value not found', err);
```

---------------------------------------

<a name="mongodb" />
### MongoDBError

Applicable when an error occurs while using MongoDB.

new MongoDBError(message[, inner_error])

__Arguments__

* `message` - any message
* `inner_error` - the Error instance that caused the current error. Stack trace will be appended.

```js
// Example
throw new errors.data.MongoDBError('Retrieved value not in expected format', err);
```

---------------------------------------

<a name="redis" />
### RedisError

Applicable when an error occurs while using redis.

new RedisError(message[, inner_error])

__Arguments__

* `message` - any message
* `inner_error` - the Error instance that caused the current error. Stack trace will be appended.

```js
// Example
throw new errors.data.RedisError('expected value not found in redis', err);
```

---------------------------------------

<a name="rollback" />
### RollbackError

Applicable when a transaction was unexpectedly rolled back.

new RollbackError(message[, inner_error])

__Arguments__

* `message` - any message
* `inner_error` - the Error instance that caused the current error. Stack trace will be appended.

```js
// Example
throw new errors.data.RollbackError('database transaction was unexpectedly rolled back', err);
```

---------------------------------------

<a name="sql" />
### SQLError

Applicable when an error occurs while using a SQL database.

new SQLError(message[, inner_error])

__Arguments__

* `message` - any message
* `inner_error` - the Error instance that caused the current error. Stack trace will be appended.

```js
// Example
throw new errors.data.SQLError('foreign key constraint violated', err);
```

---------------------------------------

<a name="transaction" />
### TransactionError

Applicable when an error unexpectedly interrupts a transaction.

new TransactionError(message[, inner_error])

__Arguments__

* `message` - any message
* `inner_error` - the Error instance that caused the current error. Stack trace will be appended.

```js
// Example
throw new errors.data.TransactionError('transaction already complete', err);
```

---------------------------------------

<a name="error" />
### Error

@@ -187,6 +350,25 @@ throw new errors.HttpStatusError(err, req);

---------------------------------------

<a name="invalidoperation" />
### InvalidOperationError

Applicable when an invalid operation occurs.

new InvalidOperationError(message[, inner_error])

__Arguments__

* `message` - any message
* `inner_error` - the Error instance that caused the current error. Stack trace will be appended.

```js
// Example
throw new errors.InvalidOperationError('divide by zero', err);
```

---------------------------------------

<a name="io" />
### IOError

@@ -301,6 +483,25 @@ throw new errors.io.FileNotFoundError("./package.json", err)

---------------------------------------

<a name="socket" />
### SocketError

Applicable when an error occurs on a socket.

new SocketError(message[, inner_error])

__Arguments__

* `message` - any message
* `inner_error` - the Error instance that caused the current error. Stack trace will be appended.

```js
// Example
throw new errors.SocketError('socket no longer available', err);
```

---------------------------------------

<a name="notfound" />
### NotFoundError

@@ -472,6 +673,25 @@ throw new errors.SyntaxError("Unexpected token a", err);

---------------------------------------

<a name="timeout" />
### TimeoutError

Applicable when an operation takes longer than the alloted amount.

new TimeoutError(time[, inner_error])

__Arguments__

* `time` - a time duration
* `inner_error` - the Error instance that caused the current error. Stack trace will be appended.

```js
// Example
throw new errors.TimeoutError('100ms', err);
```

---------------------------------------

<a name="type" />
### TypeError

@@ -680,3 +900,4 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



15 changes: 15 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -14,8 +14,10 @@ exports.AlreadyInUseError = exports.AlreadyInUse = require('./lib/alreadyInUse')
exports.ArgumentError = exports.Argument = require('./lib/argument');
exports.ArgumentNullError = exports.ArgumentNull = require('./lib/argumentNull');
exports.AuthenticationRequiredError = exports.AuthenticationRequired = require('./lib/authenticationRequired');
exports.ConnectionError = exports.helpers.generateClass('ConnectionError');
exports.Error = exports.helpers.generateClass('Error');
exports.HttpStatusError = exports.HttpStatus = require('./lib/http-status');
exports.InvalidOperationError = require('./lib/invalid-operation');
exports.NotFoundError = require('./lib/not-found');
exports.NotImplementedError = exports.helpers.generateClass('NotImplementedError'),
exports.NotSupportedError = exports.NotSupported = require('./lib/not-supported');
@@ -25,6 +27,7 @@ exports.RangeError = exports.helpers.generateClass('RangeError', { extends: Rang
exports.ReferenceError = exports.helpers.generateClass('ReferenceError', { extends: ReferenceError });
exports.StackOverflowError = exports.helpers.generateClass('StackOverflowError');
exports.SyntaxError = exports.helpers.generateClass('SyntaxError', { extends: SyntaxError });
exports.TimeoutError = require('./lib/timeout.js')
exports.TypeError = exports.helpers.generateClass('TypeError', { extends: TypeError });
exports.URIError = exports.helpers.generateClass('URIError', { extends: URIError });
exports.ValidationError = exports.Validation = require('./lib/validation');
@@ -37,6 +40,18 @@ exports.io.DriveNotFoundError = exports.helpers.generateClass('DriveNotFoundErro
exports.io.EndOfStreamError = exports.helpers.generateClass('EndOfStreamError', { extends: exports.io.IOError });
exports.io.FileLoadError = require('./lib/io/file-load');
exports.io.FileNotFoundError = require('./lib/io/file-not-found');
exports.io.SocketError = exports.helpers.generateClass('SocketError', { extends: exports.io.IOError });

exports.data = {
DataError: require('./lib/data/data')
};
exports.data.MemcachedError = exports.helpers.generateClass('MemcachedError', { extends: exports.data.DataError });
exports.data.MongoDBError = exports.helpers.generateClass('MongoDBError', { extends: exports.data.DataError });
exports.data.RedisError = exports.helpers.generateClass('RedisError', { extends: exports.data.DataError });
exports.data.RollbackError = exports.helpers.generateClass('RollbackError', { extends: exports.data.DataError });
exports.data.SQLError = exports.helpers.generateClass('SQLError', { extends: exports.data.DataError });
exports.data.TransactionError = exports.helpers.generateClass('TransactionError', { extends: exports.data.DataError });



exports.Generic = exports.helpers.generateClass('GenericError'); //deprecated
1 change: 1 addition & 0 deletions lib/data/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../helpers/class-generator')('DataError');
15 changes: 11 additions & 4 deletions lib/helpers/class-generator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var util = require('util');
var _ = require('lodash');
var globalize = require('../internal/globalize');

module.exports = function generateErrorClass(name, options){
@@ -26,9 +25,17 @@ module.exports = function generateErrorClass(name, options){
Class.captureStackTrace(this, Class);
};

var classGeneratorFn = new Function('classConstructor',
"return function " + name + "(" + options.args.join(', ') + "){ classConstructor.apply(this, arguments); };"
);
var classGeneratorFn = new Function('classConstructor', [
"return function ", name, "(", options.args.join(', '), "){",
"if(!(this instanceof ", name, ")) {",
"var instance = Object.create(", name, ".prototype);",
"classConstructor.apply(instance, arguments);",
"return instance;",
"} else {",
"classConstructor.apply(this, arguments);",
"}",
"};",
].join(''));
var Class = classGeneratorFn(classConstructor);

util.inherits(Class, options.extends);
Loading