https://github.com/boneskull/errorist
If you don't have an Error, errorist gives you one
https://github.com/boneskull/errorist
Last synced: 11 months ago
JSON representation
If you don't have an Error, errorist gives you one
- Host: GitHub
- URL: https://github.com/boneskull/errorist
- Owner: boneskull
- License: mit
- Archived: true
- Created: 2015-08-11T09:07:40.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-07-26T15:20:40.000Z (over 8 years ago)
- Last Synced: 2025-02-23T03:03:16.302Z (12 months ago)
- Language: JavaScript
- Homepage: http://boneskull.com/errorist
- Size: 76.2 KB
- Stars: 1
- Watchers: 3
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# errorist [](http://badge.fury.io/js/errorist) [](https://travis-ci.org/boneskull/errorist) [](https://www.codacy.com/app/boneskull/errorist)
> If you don't have an Error, errorist gives you one
## Install
```shell
$ npm install errorist
```
## Usage
```js
var errorist = require('errorist');
function asyncFunc(callback) {
process.nextTick(function() {
callback('this is not an Error; it is a string');
});
}
asyncFunc(function(err) {
if (err) {
// you would never do a thing like throw a string, right?
throw errorist(err);
}
});
// or with promises
require('bluebird').promisify(asyncFunc)()
.catch(err) {
// stack trace FTW
throw errorist(err);
});
```
## Notes
errorist's flow is a bit like this:
- If the value is an `Error`
- `return` it.
- If the value is a non-`null` object or function
- and its `message` property is a `string`
- `return` a new `Error` with the `message`.
- otherwise
- stringify the object into JSON
- upon success
- `return` the stringified object as the `Error`'s `message`.
- otherwise
- `return` an empty `Error` instance.
- Otherwise
- `return` an `Error` instance with the primitive, `null`, or `undefined` value as its message.
## License
© 2015 [Christopher Hiller](https://boneskull.com). Licensed MIT.