Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

make-error-cause

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

make-error-cause

Make your own nested error types!

  • 2.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
179K
decreased by-59.99%
Maintainers
1
Weekly downloads
 
Created

What is make-error-cause?

The make-error-cause npm package is designed to simplify the creation of custom error classes in JavaScript, while also allowing you to maintain the original error cause. This is particularly useful for error handling in complex applications where you need to preserve the stack trace and context of the original error.

What are make-error-cause's main functionalities?

Creating Custom Error Classes

This feature allows you to create custom error classes that can encapsulate an original error. The custom error class extends from `makeErrorCause.BaseError`, which helps in maintaining the original error's stack trace and context.

const makeErrorCause = require('make-error-cause');

class MyCustomError extends makeErrorCause.BaseError {
  constructor(message, cause) {
    super(message, cause);
    this.name = 'MyCustomError';
  }
}

try {
  throw new Error('Original error');
} catch (err) {
  throw new MyCustomError('Custom error message', err);
}

Preserving Original Error Cause

This feature demonstrates how to preserve the original error cause when throwing a new custom error. This is useful for debugging and logging, as it provides a complete error stack trace.

const makeErrorCause = require('make-error-cause');

class DatabaseError extends makeErrorCause.BaseError {
  constructor(message, cause) {
    super(message, cause);
    this.name = 'DatabaseError';
  }
}

try {
  throw new Error('Connection failed');
} catch (err) {
  throw new DatabaseError('Database operation failed', err);
}

Other packages similar to make-error-cause

Keywords

FAQs

Package last updated on 26 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc