Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sindresorhus/aggregate-error
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.0.1
Choose a base ref
...
head repository: sindresorhus/aggregate-error
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v5.0.0
Choose a head ref
  • 3 commits
  • 8 files changed
  • 1 contributor

Commits on Jul 8, 2022

  1. Meta tweaks

    sindresorhus committed Jul 8, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    40f346d View commit details

Commits on Sep 14, 2023

  1. Require Node.js 18

    Fixes #22
    sindresorhus committed Sep 14, 2023
    Copy the full SHA
    6e107f6 View commit details
  2. 5.0.0

    sindresorhus committed Sep 14, 2023
    Copy the full SHA
    8b09cac View commit details
Showing with 39 additions and 30 deletions.
  1. +4 −0 .github/funding.yml
  2. +3 −0 .github/security.md
  3. +4 −4 .github/workflows/main.yml
  4. +5 −5 index.js
  5. +2 −2 index.test-d.ts
  6. +11 −9 package.json
  7. +2 −2 readme.md
  8. +8 −8 test.js
4 changes: 4 additions & 0 deletions .github/funding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github: sindresorhus
open_collective: sindresorhus
tidelift: npm/aggregate-error
custom: https://sindresorhus.com/donate
3 changes: 3 additions & 0 deletions .github/security.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Security Policy

To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -10,11 +10,11 @@ jobs:
fail-fast: false
matrix:
node-version:
- 14
- 12
- 20
- 18
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import indentString from 'indent-string';
import cleanStack from 'clean-stack';

const cleanInternalStack = stack => stack.replace(/\s+at .*aggregate-error\/index.js:\d+:\d+\)?/g, '');
const cleanInternalStack = stack => stack.replaceAll(/\s+at .*aggregate-error\/index.js:\d+:\d+\)?/g, '');

export default class AggregateError extends Error {
#errors;
@@ -27,10 +27,10 @@ export default class AggregateError extends Error {
});

let message = errors
.map(error => {
.map(error =>
// The `stack` property is not standardized, so we can't assume it exists
return typeof error.stack === 'string' && error.stack.length > 0 ? cleanInternalStack(cleanStack(error.stack)) : String(error);
})
typeof error.stack === 'string' && error.stack.length > 0 ? cleanInternalStack(cleanStack(error.stack)) : String(error),
)
.join('\n');
message = '\n' + indentString(message, 4);
super(message);
@@ -39,6 +39,6 @@ export default class AggregateError extends Error {
}

get errors() {
return this.#errors.slice();
return [...this.#errors];
}
}
4 changes: 2 additions & 2 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import AggregateError from './index.js';
const aggregateError = new AggregateError([
new Error('foo'),
{foo: 'bar'},
'bar'
'bar',
]);
expectAssignable<Iterable<Error>>(aggregateError.errors);
expectType<IterableIterator<Error>>(aggregateError.errors[Symbol.iterator]());
@@ -23,7 +23,7 @@ class CustomError extends Error {
}
}
const customAggregateError = new AggregateError<CustomError>([
new CustomError('foo')
new CustomError('foo'),
]);

for (const error of customAggregateError.errors) {
20 changes: 11 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aggregate-error",
"version": "4.0.1",
"version": "5.0.0",
"description": "Create an error from multiple errors",
"license": "MIT",
"repository": "sindresorhus/aggregate-error",
@@ -11,13 +11,15 @@
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"exports": {
"types": "./index.d.ts",
"default": "./index.js"
},
"engines": {
"node": ">=12"
"node": ">=18"
},
"scripts": {
"//test": "xo && ava && tsd",
"test": "ava && tsd"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
@@ -34,12 +36,12 @@
"iterator"
],
"dependencies": {
"clean-stack": "^4.0.0",
"clean-stack": "^5.2.0",
"indent-string": "^5.0.0"
},
"devDependencies": {
"ava": "^3.15.0",
"tsd": "^0.14.0",
"xo": "^0.38.2"
"ava": "^5.3.1",
"tsd": "^0.29.0",
"xo": "^0.56.0"
}
}
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@

## Install

```
$ npm install aggregate-error
```sh
npm install aggregate-error
```

## Usage
16 changes: 8 additions & 8 deletions test.js
Original file line number Diff line number Diff line change
@@ -7,11 +7,11 @@ test('main', t => {
'bar',
{
message: 'baz',
code: 'EBAZ'
code: 'EBAZ',
},
{
code: 'EQUX'
}
code: 'EQUX',
},
]);

console.log(error);
@@ -23,7 +23,7 @@ test('main', t => {
new Error('foo'),
new Error('bar'),
Object.assign(new Error('baz'), {code: 'EBAZ'}),
Object.assign(new Error(), {code: 'EQUX'}) // eslint-disable-line unicorn/error-message
Object.assign(new Error(), {code: 'EQUX'}), // eslint-disable-line unicorn/error-message
]);
});

@@ -38,7 +38,7 @@ test('gracefully handle Error instances without a stack', t => {

const error = new AggregateError([
new Error('foo'),
new StacklessError('stackless')
new StacklessError('stackless'),
]);

console.log(error);
@@ -48,7 +48,7 @@ test('gracefully handle Error instances without a stack', t => {

t.deepEqual([...error.errors], [
new Error('foo'),
new StacklessError('stackless')
new StacklessError('stackless'),
]);
});

@@ -63,7 +63,7 @@ test('gracefully handle Error instances with empty stack', t => {

const error = new AggregateError([
new Error('foo'),
new EmptyStackError('emptystack')
new EmptyStackError('emptystack'),
]);

console.log(error);
@@ -73,6 +73,6 @@ test('gracefully handle Error instances with empty stack', t => {

t.deepEqual([...error.errors], [
new Error('foo'),
new EmptyStackError('emptystack')
new EmptyStackError('emptystack'),
]);
});