What is combine-errors?
The combine-errors npm package allows you to combine multiple error objects into a single error object. This can be useful in scenarios where you need to aggregate multiple errors and handle them as a single entity.
What are combine-errors's main functionalities?
Combining Multiple Errors
This feature allows you to combine multiple error objects into a single error object. The combined error will contain information from all the individual errors.
const combineErrors = require('combine-errors');
const error1 = new Error('First error');
const error2 = new Error('Second error');
const combinedError = combineErrors([error1, error2]);
console.log(combinedError);
Handling Nested Errors
This feature allows you to handle nested errors by combining them into a single error object. This can be useful when dealing with complex error scenarios where errors are nested within each other.
const combineErrors = require('combine-errors');
const error1 = new Error('First error');
const nestedError = combineErrors([new Error('Nested error 1'), new Error('Nested error 2')]);
const combinedError = combineErrors([error1, nestedError]);
console.log(combinedError);
Other packages similar to combine-errors
aggregate-error
The aggregate-error package allows you to create an error that aggregates multiple errors. It provides a similar functionality to combine-errors but with a different API. AggregateError is a built-in error type in JavaScript, and this package provides a way to use it easily.
combine-errors
Simple, dependency-free way to combine multiple errors into one.
This is useful for handling multiple asynchronous errors, where you want to catch all the errors and combine them to return just a single error.
Features
error instanceof Error === true
- composable:
error(error([err1, err2]), err3)
- stack and message are combined in a nice way
- array-like object, so you can access the original errors by looping over the error
- If you just have one error, it looks exactly like one error meaning,
error(err).message === err.message && error(err).stack === err.stack
- zero dependencies
- should work in the browser, though I haven't tested it yet
Installation
npm install combine-errors
Usage
var error = require('combine-errors')
var err = error([
new Error('boom'),
new Error('kablam')
])
throw err
License
MIT