make-error-cause
TypeScript icon, indicating that this package has built-in type declarations

2.3.0 • Public • Published

Make Error Cause

NPM version NPM downloads Build status Test coverage

Make your own nested errors.

Features

  • Compatible with node.js and browsers
  • Works with instanceof
  • Automatic full stack traces in node.js (supports inspect())
  • Output full stack trace with fullStack(err)
  • Extends make-error

Installation

npm install make-error-cause --save

Usage

import { BaseError, fullStack } from "make-error-cause";
 
class CustomError extends BaseError {
  constructor(message, cause) {
    super(message, cause);
  }
}
 
const error = new Error("Boom!");
const customError = new CustomError("Another boom!", error);
 
console.log(customError); // Automatically prints full stack trace using `fullStack(this)`.
console.log(customError.cause); // Check causes via the `.cause` property.
 
console.log(customError instanceof Error); //=> true

Attribution

Inspired by verror, and others, but created lighter and without core dependencies for browser usage.

Other references:

License

Apache 2.0

Dependents (73)

Package Sidebar

Install

npm i make-error-cause

Weekly Downloads

430,596

Version

2.3.0

License

Apache-2.0

Unpacked Size

8.28 kB

Total Files

7

Last publish

Collaborators

  • blakeembrey