Socket
Socket
Sign inDemoInstall

aggregate-error

Package Overview
Dependencies
2
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    aggregate-error

Create an error from multiple errors


Version published
Weekly downloads
24M
decreased by-7.42%
Maintainers
1
Install size
14.9 kB
Created
Weekly downloads
 

Package description

What is aggregate-error?

The aggregate-error package is used to create an Error instance that aggregates multiple errors into a single error object. This can be useful when you have several operations that may each throw errors, and you want to collect all of those errors into a single error object that can be thrown, returned, or logged.

What are aggregate-error's main functionalities?

Aggregating multiple errors

This feature allows you to collect multiple errors into a single error object. The code sample demonstrates how to create an instance of AggregateError with an array of Error objects and then throw it.

const AggregateError = require('aggregate-error');

const errors = [
  new Error('First error'),
  new Error('Second error')
];

const aggregatedError = new AggregateError(errors);

throw aggregatedError;

Iterating over aggregated errors

This feature allows you to iterate over the individual errors within an AggregateError instance. The code sample shows how to loop through each error using a for...of loop and log them to the console.

const AggregateError = require('aggregate-error');

const errors = [
  new Error('First error'),
  new Error('Second error')
];

const aggregatedError = new AggregateError(errors);

for (const error of aggregatedError) {
  console.error(error);
}

Other packages similar to aggregate-error

Readme

Source

aggregate-error Build Status

Create an error from multiple errors

Install

$ npm install --save aggregate-error

Usage

const AggregateError = require('aggregate-error');

const err = new AggregateError([new Error('foo'), 'bar']);

throw err;
/*
AggregateError:
    Error: foo
        at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:33)
    Error: bar
        at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:13)
    at AggregateError (/Users/sindresorhus/dev/aggregate-error/index.js:19:3)
    at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:13)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.runMain (module.js:590:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
*/

for (const el of err) {
	console.log(el);
}
//=> [Error: foo]
//=> [Error: bar]

API

AggregateError(errors)

Returns an Error that is also an iterator for the individual errors.

errors

Type: Iterable<Error|string>

License

MIT © Sindre Sorhus

Keywords

FAQs

Last updated on 13 Jan 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc