1. make-error-cause
Make your own nested error types!
make-error-cause
Package: make-error-cause
Created by: blakeembrey
Last modified: Sun, 19 Jun 2022 15:32:25 GMT
Version: 2.3.0
License: Apache-2.0
Downloads: 2,034,651
Repository: https://github.com/blakeembrey/make-error-cause

Install

npm install make-error-cause
yarn add make-error-cause

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

Dependencies

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code