commit
This commit is contained in:
parent
70e2f7a8aa
commit
008d2f30d7
675 changed files with 189892 additions and 0 deletions
2
node_modules/failure/.npmignore
generated
vendored
Normal file
2
node_modules/failure/.npmignore
generated
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
coverage
|
||||
node_modules
|
20
node_modules/failure/.travis.yml
generated
vendored
Normal file
20
node_modules/failure/.travis.yml
generated
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
language: node_js
|
||||
node_js:
|
||||
- "0.12"
|
||||
- "0.10"
|
||||
- "0.8"
|
||||
- "iojs"
|
||||
before_install:
|
||||
- "npm install -g npm@1.4.x"
|
||||
script:
|
||||
- "npm run test-travis"
|
||||
after_script:
|
||||
- "npm install coveralls@2.11.x && cat coverage/lcov.info | coveralls"
|
||||
matrix:
|
||||
fast_finish: true
|
||||
notifications:
|
||||
irc:
|
||||
channels:
|
||||
- "irc.freenode.org#unshift"
|
||||
on_success: change
|
||||
on_failure: change
|
22
node_modules/failure/LICENSE
generated
vendored
Normal file
22
node_modules/failure/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Unshift.io, Arnout Kazemier, the Contributors.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
|
82
node_modules/failure/README.md
generated
vendored
Normal file
82
node_modules/failure/README.md
generated
vendored
Normal file
|
@ -0,0 +1,82 @@
|
|||
# failure
|
||||
|
||||
[![Made by unshift][made-by]](http://unshift.io)[![Version npm][version]](http://browsenpm.org/package/failure)[![Build Status][build]](https://travis-ci.org/unshiftio/failure)[![Dependencies][david]](https://david-dm.org/unshiftio/failure)[![Coverage Status][cover]](https://coveralls.io/r/unshiftio/failure?branch=master)[![IRC channel][irc]](http://webchat.freenode.net/?channels=unshift)
|
||||
|
||||
[made-by]: https://img.shields.io/badge/made%20by-unshift-00ffcc.svg?style=flat-square
|
||||
[version]: https://img.shields.io/npm/v/failure.svg?style=flat-square
|
||||
[build]: https://img.shields.io/travis/unshiftio/failure/master.svg?style=flat-square
|
||||
[david]: https://img.shields.io/david/unshiftio/failure.svg?style=flat-square
|
||||
[cover]: https://img.shields.io/coveralls/unshiftio/failure/master.svg?style=flat-square
|
||||
[irc]: https://img.shields.io/badge/IRC-irc.freenode.net%23unshift-00a8ff.svg?style=flat-square
|
||||
|
||||
Failure is a small helper library which allows you to easily generate custom
|
||||
error objects which can hold addition properties which could be helpful for
|
||||
debugging your application. In addition to that, it automatically adds a missing
|
||||
`toJSON` function to the Error object so you can actually get the message and
|
||||
stack trace once you `JSON.stringify` the error instance.
|
||||
|
||||
## Installation
|
||||
|
||||
The module is written with browsers and servers in mind and should run in any
|
||||
environment that runs ES3. The module it self is released in the public npm
|
||||
registry and can be installed using:
|
||||
|
||||
```
|
||||
npm install --save failure
|
||||
```
|
||||
|
||||
The `--save` flag tells npm to automatically add the installed version to your
|
||||
`package.json` file as new dependency.
|
||||
|
||||
## Usage
|
||||
|
||||
First of all, start with including this module in your code:
|
||||
|
||||
```js
|
||||
'use strict';
|
||||
|
||||
var failure = require('failure');
|
||||
```
|
||||
|
||||
Now every time you want to pass or create a `new Error` instance, you can use
|
||||
the `failure` function to generate the error for you. The failure method accepts
|
||||
2 arguments:
|
||||
|
||||
1. An `Error` instance that just needs extra props, or a `string` that should be
|
||||
transformed to an `Error`. Please do note that when using a string you will
|
||||
have an extra trace in your stack trace as the stack trace will be made inside
|
||||
the `failure` function instead of where you called the `failure` function.
|
||||
2. An object with extra properties that should be introduced on the supplied or
|
||||
generated `Error` instance. These properties will not override existing
|
||||
properties on the `Error` instance.
|
||||
|
||||
Before the function returns the generated `Error` instance it checks if it also
|
||||
needs to add the missing `.toJSON` method.
|
||||
|
||||
Below is a small usage example on how you could use this to provide extra
|
||||
information when things start failing when you make an HTTP request somewhere.
|
||||
If request something with an incorrect status code, you might want to know what
|
||||
statusCode was received, so we can easily add that to the Error object. Same as
|
||||
parse errors for JSON, you probably want to know what you received and failed.
|
||||
|
||||
```js
|
||||
request('https://googlllll.com', function (err, res, body) {
|
||||
if (err) return next(err);
|
||||
if (res.statusCode !== 200) return next(failure('Invalid statusCode'), {
|
||||
statusCode: res.statusCode
|
||||
});
|
||||
|
||||
try { body = JSON.parse(body); }
|
||||
catch (e) {
|
||||
return next(failure(e, {
|
||||
body: body
|
||||
}));
|
||||
}
|
||||
|
||||
next(undefined, body);
|
||||
})
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
53
node_modules/failure/index.js
generated
vendored
Normal file
53
node_modules/failure/index.js
generated
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
'use strict';
|
||||
|
||||
var has = Object.prototype.hasOwnProperty;
|
||||
|
||||
/**
|
||||
* Return an object with all the information that should be in the JSON output.
|
||||
* It doesn't matter if we list keys that might not be in the err as the
|
||||
* JSON.stringify will remove properties who's values are set to `undefined`. So
|
||||
* we want to make sure that we include some common properties.
|
||||
*
|
||||
* @returns {Object}
|
||||
* @api public
|
||||
*/
|
||||
function toJSON() {
|
||||
var obj = { message: this.message, stack: this.stack }, key;
|
||||
|
||||
for (key in this) {
|
||||
if (
|
||||
has.call(this, key)
|
||||
&& 'function' !== typeof this[key]
|
||||
) {
|
||||
obj[key] = this[key];
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a custom wrapped error object.
|
||||
*
|
||||
* @param {String|Error} err Error that needs to have additional properties.
|
||||
* @param {Object} props Addition properties for the Error.
|
||||
* @returns {Error} The generated or returned Error instance
|
||||
* @api public
|
||||
*/
|
||||
module.exports = function failure(err, props) {
|
||||
if (!err) err = 'Unspecified error';
|
||||
if ('string' === typeof err) err = new Error(err);
|
||||
|
||||
if (props) for (var prop in props) {
|
||||
if (!(prop in err) && has.call(props, prop)) {
|
||||
err[prop] = props[prop];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Add a custom `toJSON` method so we can generate a useful output when
|
||||
// running these objects through JSON.stringify.
|
||||
//
|
||||
if ('function' !== typeof err.toJSON) err.toJSON = toJSON;
|
||||
return err;
|
||||
};
|
39
node_modules/failure/package.json
generated
vendored
Normal file
39
node_modules/failure/package.json
generated
vendored
Normal file
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
"name": "failure",
|
||||
"version": "1.1.1",
|
||||
"description": "Easily generate \"custom\" error objects with addition properties which can be stringfied with JSON.stringify",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"100%": "istanbul check-coverage --statements 100 --functions 100 --lines 100 --branches 100",
|
||||
"test": "mocha test.js",
|
||||
"watch": "mocha --watch test.js",
|
||||
"coverage": "istanbul cover ./node_modules/.bin/_mocha -- test.js",
|
||||
"test-travis": "istanbul cover node_modules/.bin/_mocha --report lcovonly -- test.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/unshiftio/failure"
|
||||
},
|
||||
"keywords": [
|
||||
"failure",
|
||||
"error",
|
||||
"errs",
|
||||
"err",
|
||||
"errors",
|
||||
"fail",
|
||||
"throw",
|
||||
"custom"
|
||||
],
|
||||
"author": "Arnout Kazemier",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/unshiftio/failure/issues"
|
||||
},
|
||||
"homepage": "https://github.com/unshiftio/failure",
|
||||
"devDependencies": {
|
||||
"assume": "1.2.x",
|
||||
"istanbul": "0.3.x",
|
||||
"mocha": "2.2.x",
|
||||
"pre-commit": "1.0.x"
|
||||
}
|
||||
}
|
83
node_modules/failure/test.js
generated
vendored
Normal file
83
node_modules/failure/test.js
generated
vendored
Normal file
|
@ -0,0 +1,83 @@
|
|||
describe('failure', function () {
|
||||
'use strict';
|
||||
|
||||
var assume = require('assume')
|
||||
, failure = require('./');
|
||||
|
||||
it('returns an Error instance with supplied str as message', function () {
|
||||
var err = failure('what');
|
||||
|
||||
assume(err).is.instanceOf(Error);
|
||||
assume(err.message).equals('what');
|
||||
});
|
||||
|
||||
it('does not merge over existing properties', function () {
|
||||
var err = failure(new Error('what'), { foo: 'bar', message: 'hi' });
|
||||
|
||||
assume(err.message).equals('what');
|
||||
assume(err.foo).equals('bar');
|
||||
});
|
||||
|
||||
it('defaults to unspecified error', function () {
|
||||
assume(failure().message).includes('error');
|
||||
});
|
||||
|
||||
it('accepts Object.create(null)', function () {
|
||||
var obj = Object.create(null)
|
||||
, err;
|
||||
|
||||
obj.foo = 'bar';
|
||||
obj.message = 'hi';
|
||||
|
||||
err = failure(new Error('what'), obj);
|
||||
|
||||
assume(err.message).equals('what');
|
||||
assume(err.foo).equals('bar');
|
||||
});
|
||||
|
||||
describe('#toJSON', function () {
|
||||
it('adds the `toJSON` function', function () {
|
||||
assume(failure().toJSON).is.a('function');
|
||||
});
|
||||
|
||||
it('returns the stack and message', function () {
|
||||
var err = failure('hi').toJSON();
|
||||
|
||||
assume(err).is.a('object');
|
||||
assume(err.message).equals('hi');
|
||||
assume(err.stack).is.a('string');
|
||||
});
|
||||
|
||||
it('includes non standard values if defined on the error', function () {
|
||||
var err = failure('hi', { statusCode: 200, what: 'why' })
|
||||
, res = err.toJSON();
|
||||
|
||||
assume(err.what).equals('why');
|
||||
assume(res.what).is.equals('why');
|
||||
assume(res.statusCode).equals(200);
|
||||
assume(err.statusCode).equals(200);
|
||||
});
|
||||
|
||||
it('includes properties that were previously specified on a given error', function () {
|
||||
var err = new Error('fools')
|
||||
, res;
|
||||
|
||||
err.warning = true;
|
||||
res = failure(err, { what: 'lol' }).toJSON();
|
||||
|
||||
assume(res.what).equals('lol');
|
||||
assume(res.warning).equals(true);
|
||||
assume(res.message).equals('fools');
|
||||
});
|
||||
|
||||
it('does not override existing toJSON functions', function () {
|
||||
var err = new Error('lol');
|
||||
|
||||
err.toJSON = function () {
|
||||
return 'run, fools!';
|
||||
};
|
||||
|
||||
assume(failure(err).toJSON()).equals('run, fools!');
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue