Skip to content

flex-development/aggregate-error-ponyfill

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

aggregate-error-ponyfill

npm codecov module type: cjs+esm license conventional commits typescript vitest yarn

AggregateError ponyfill.

Contents

What is this?

This package is an ECMAScript Proposal spec-compliant ponyfill for AggregateError.

When should I use this?

Use this package when you want to throw AggregateError objects in unsupported environments (< es2021).

Install

yarn add @flex-development/aggregate-error-ponyfill

From Git:

yarn add @flex-development/aggregate-error-ponyfill@flex-development/aggregate-error-ponyfill
See Git - Protocols | Yarn  for details on requesting a specific branch, commit, or tag.

Use

import AggregateError from '@flex-development/aggregate-error-ponyfill'

try {
  throw new AggregateError([new Error('some error')], 'oh no!')
} catch (e) {
  console.debug(e instanceof AggregateError) // true
  console.error(e.name)                      // 'AggregateError'
  console.error(e.message)                   // 'oh no!'
  console.error(e.errors)                    // [Error: 'some error']
}

API

This package exports no identifiers.

The default export is AggregateError.

new AggregateError<T, C>(errors: Iterable<T>, message?: string, options?: Options<C>)

Wrap several errors in a single error so that multiple errors can be reported by an operation.

errors

An iterable of errors.

message

An optional human-readable description of the aggregate error.

options

An object that has the following properties:

cause

The specific cause of the aggregate error.

When catching and re-throwing an error with a more-specific or useful error message, this property can be used to pass the original error.

Types

This package is fully typed with TypeScript.

Interfaces

Contribute

See CONTRIBUTING.md.