aboutsummaryrefslogtreecommitdiff
path: root/node_modules/error-ex
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/error-ex')
-rw-r--r--node_modules/error-ex/LICENSE21
-rw-r--r--node_modules/error-ex/README.md144
-rw-r--r--node_modules/error-ex/index.js141
-rw-r--r--node_modules/error-ex/package.json90
4 files changed, 396 insertions, 0 deletions
diff --git a/node_modules/error-ex/LICENSE b/node_modules/error-ex/LICENSE
new file mode 100644
index 0000000..0a5f461
--- /dev/null
+++ b/node_modules/error-ex/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2015 JD Ballard
+
+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.
diff --git a/node_modules/error-ex/README.md b/node_modules/error-ex/README.md
new file mode 100644
index 0000000..97f744a
--- /dev/null
+++ b/node_modules/error-ex/README.md
@@ -0,0 +1,144 @@
+# node-error-ex [![Travis-CI.org Build Status](https://img.shields.io/travis/Qix-/node-error-ex.svg?style=flat-square)](https://travis-ci.org/Qix-/node-error-ex) [![Coveralls.io Coverage Rating](https://img.shields.io/coveralls/Qix-/node-error-ex.svg?style=flat-square)](https://coveralls.io/r/Qix-/node-error-ex)
+> Easily subclass and customize new Error types
+
+## Examples
+To include in your project:
+```javascript
+var errorEx = require('error-ex');
+```
+
+To create an error message type with a specific name (note, that `ErrorFn.name`
+will not reflect this):
+```javascript
+var JSONError = errorEx('JSONError');
+
+var err = new JSONError('error');
+err.name; //-> JSONError
+throw err; //-> JSONError: error
+```
+
+To add a stack line:
+```javascript
+var JSONError = errorEx('JSONError', {fileName: errorEx.line('in %s')});
+
+var err = new JSONError('error')
+err.fileName = '/a/b/c/foo.json';
+throw err; //-> (line 2)-> in /a/b/c/foo.json
+```
+
+To append to the error message:
+```javascript
+var JSONError = errorEx('JSONError', {fileName: errorEx.append('in %s')});
+
+var err = new JSONError('error');
+err.fileName = '/a/b/c/foo.json';
+throw err; //-> JSONError: error in /a/b/c/foo.json
+```
+
+## API
+
+#### `errorEx([name], [properties])`
+Creates a new ErrorEx error type
+
+- `name`: the name of the new type (appears in the error message upon throw;
+ defaults to `Error.name`)
+- `properties`: if supplied, used as a key/value dictionary of properties to
+ use when building up the stack message. Keys are property names that are
+ looked up on the error message, and then passed to function values.
+ - `line`: if specified and is a function, return value is added as a stack
+ entry (error-ex will indent for you). Passed the property value given
+ the key.
+ - `stack`: if specified and is a function, passed the value of the property
+ using the key, and the raw stack lines as a second argument. Takes no
+ return value (but the stack can be modified directly).
+ - `message`: if specified and is a function, return value is used as new
+ `.message` value upon get. Passed the property value of the property named
+ by key, and the existing message is passed as the second argument as an
+ array of lines (suitable for multi-line messages).
+
+Returns a constructor (Function) that can be used just like the regular Error
+constructor.
+
+```javascript
+var errorEx = require('error-ex');
+
+var BasicError = errorEx();
+
+var NamedError = errorEx('NamedError');
+
+// --
+
+var AdvancedError = errorEx('AdvancedError', {
+ foo: {
+ line: function (value, stack) {
+ if (value) {
+ return 'bar ' + value;
+ }
+ return null;
+ }
+ }
+}
+
+var err = new AdvancedError('hello, world');
+err.foo = 'baz';
+throw err;
+
+/*
+ AdvancedError: hello, world
+ bar baz
+ at tryReadme() (readme.js:20:1)
+*/
+```
+
+#### `errorEx.line(str)`
+Creates a stack line using a delimiter
+
+> This is a helper function. It is to be used in lieu of writing a value object
+> for `properties` values.
+
+- `str`: The string to create
+ - Use the delimiter `%s` to specify where in the string the value should go
+
+```javascript
+var errorEx = require('error-ex');
+
+var FileError = errorEx('FileError', {fileName: errorEx.line('in %s')});
+
+var err = new FileError('problem reading file');
+err.fileName = '/a/b/c/d/foo.js';
+throw err;
+
+/*
+ FileError: problem reading file
+ in /a/b/c/d/foo.js
+ at tryReadme() (readme.js:7:1)
+*/
+```
+
+#### `errorEx.append(str)`
+Appends to the `error.message` string
+
+> This is a helper function. It is to be used in lieu of writing a value object
+> for `properties` values.
+
+- `str`: The string to append
+ - Use the delimiter `%s` to specify where in the string the value should go
+
+```javascript
+var errorEx = require('error-ex');
+
+var SyntaxError = errorEx('SyntaxError', {fileName: errorEx.append('in %s')});
+
+var err = new SyntaxError('improper indentation');
+err.fileName = '/a/b/c/d/foo.js';
+throw err;
+
+/*
+ SyntaxError: improper indentation in /a/b/c/d/foo.js
+ at tryReadme() (readme.js:7:1)
+*/
+```
+
+## License
+Licensed under the [MIT License](http://opensource.org/licenses/MIT).
+You can find a copy of it in [LICENSE](LICENSE).
diff --git a/node_modules/error-ex/index.js b/node_modules/error-ex/index.js
new file mode 100644
index 0000000..4fb20b4
--- /dev/null
+++ b/node_modules/error-ex/index.js
@@ -0,0 +1,141 @@
+'use strict';
+
+var util = require('util');
+var isArrayish = require('is-arrayish');
+
+var errorEx = function errorEx(name, properties) {
+ if (!name || name.constructor !== String) {
+ properties = name || {};
+ name = Error.name;
+ }
+
+ var errorExError = function ErrorEXError(message) {
+ if (!this) {
+ return new ErrorEXError(message);
+ }
+
+ message = message instanceof Error
+ ? message.message
+ : (message || this.message);
+
+ Error.call(this, message);
+ Error.captureStackTrace(this, errorExError);
+
+ this.name = name;
+
+ Object.defineProperty(this, 'message', {
+ configurable: true,
+ enumerable: false,
+ get: function () {
+ var newMessage = message.split(/\r?\n/g);
+
+ for (var key in properties) {
+ if (!properties.hasOwnProperty(key)) {
+ continue;
+ }
+
+ var modifier = properties[key];
+
+ if ('message' in modifier) {
+ newMessage = modifier.message(this[key], newMessage) || newMessage;
+ if (!isArrayish(newMessage)) {
+ newMessage = [newMessage];
+ }
+ }
+ }
+
+ return newMessage.join('\n');
+ },
+ set: function (v) {
+ message = v;
+ }
+ });
+
+ var overwrittenStack = null;
+
+ var stackDescriptor = Object.getOwnPropertyDescriptor(this, 'stack');
+ var stackGetter = stackDescriptor.get;
+ var stackValue = stackDescriptor.value;
+ delete stackDescriptor.value;
+ delete stackDescriptor.writable;
+
+ stackDescriptor.set = function (newstack) {
+ overwrittenStack = newstack;
+ };
+
+ stackDescriptor.get = function () {
+ var stack = (overwrittenStack || ((stackGetter)
+ ? stackGetter.call(this)
+ : stackValue)).split(/\r?\n+/g);
+
+ // starting in Node 7, the stack builder caches the message.
+ // just replace it.
+ if (!overwrittenStack) {
+ stack[0] = this.name + ': ' + this.message;
+ }
+
+ var lineCount = 1;
+ for (var key in properties) {
+ if (!properties.hasOwnProperty(key)) {
+ continue;
+ }
+
+ var modifier = properties[key];
+
+ if ('line' in modifier) {
+ var line = modifier.line(this[key]);
+ if (line) {
+ stack.splice(lineCount++, 0, ' ' + line);
+ }
+ }
+
+ if ('stack' in modifier) {
+ modifier.stack(this[key], stack);
+ }
+ }
+
+ return stack.join('\n');
+ };
+
+ Object.defineProperty(this, 'stack', stackDescriptor);
+ };
+
+ if (Object.setPrototypeOf) {
+ Object.setPrototypeOf(errorExError.prototype, Error.prototype);
+ Object.setPrototypeOf(errorExError, Error);
+ } else {
+ util.inherits(errorExError, Error);
+ }
+
+ return errorExError;
+};
+
+errorEx.append = function (str, def) {
+ return {
+ message: function (v, message) {
+ v = v || def;
+
+ if (v) {
+ message[0] += ' ' + str.replace('%s', v.toString());
+ }
+
+ return message;
+ }
+ };
+};
+
+errorEx.line = function (str, def) {
+ return {
+ line: function (v) {
+ v = v || def;
+
+ if (v) {
+ return str.replace('%s', v.toString());
+ }
+
+ return null;
+ }
+ };
+};
+
+module.exports = errorEx;
diff --git a/node_modules/error-ex/package.json b/node_modules/error-ex/package.json
new file mode 100644
index 0000000..9643dcf
--- /dev/null
+++ b/node_modules/error-ex/package.json
@@ -0,0 +1,90 @@
+{
+ "_args": [
+ [
+ "error-ex@1.3.2",
+ "/home/dstaesse/git/website"
+ ]
+ ],
+ "_development": true,
+ "_from": "error-ex@1.3.2",
+ "_id": "error-ex@1.3.2",
+ "_inBundle": false,
+ "_integrity": "sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==",
+ "_location": "/error-ex",
+ "_phantomChildren": {},
+ "_requested": {
+ "type": "version",
+ "registry": true,
+ "raw": "error-ex@1.3.2",
+ "name": "error-ex",
+ "escapedName": "error-ex",
+ "rawSpec": "1.3.2",
+ "saveSpec": null,
+ "fetchSpec": "1.3.2"
+ },
+ "_requiredBy": [
+ "/parse-json"
+ ],
+ "_resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz",
+ "_spec": "1.3.2",
+ "_where": "/home/dstaesse/git/website",
+ "bugs": {
+ "url": "https://github.com/qix-/node-error-ex/issues"
+ },
+ "dependencies": {
+ "is-arrayish": "^0.2.1"
+ },
+ "description": "Easy error subclassing and stack customization",
+ "devDependencies": {
+ "coffee-script": "^1.9.3",
+ "coveralls": "^2.11.2",
+ "istanbul": "^0.3.17",
+ "mocha": "^2.2.5",
+ "should": "^7.0.1",
+ "xo": "^0.7.1"
+ },
+ "files": [
+ "index.js"
+ ],
+ "homepage": "https://github.com/qix-/node-error-ex#readme",
+ "keywords": [
+ "error",
+ "errors",
+ "extend",
+ "extending",
+ "extension",
+ "subclass",
+ "stack",
+ "custom"
+ ],
+ "license": "MIT",
+ "maintainers": [
+ {
+ "name": "Josh Junon",
+ "email": "i.am.qix@gmail.com",
+ "url": "github.com/qix-"
+ },
+ {
+ "name": "Sindre Sorhus",
+ "email": "sindresorhus@gmail.com",
+ "url": "sindresorhus.com"
+ }
+ ],
+ "name": "error-ex",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/qix-/node-error-ex.git"
+ },
+ "scripts": {
+ "pretest": "xo",
+ "test": "mocha --compilers coffee:coffee-script/register"
+ },
+ "version": "1.3.2",
+ "xo": {
+ "rules": {
+ "operator-linebreak": [
+ 0
+ ]
+ }
+ }
+}