Skip to content

Commit

Permalink
refactor(internal): deprecate makeAggregateError in favor of Aggregat… (
Browse files Browse the repository at this point in the history
#9275)

closes: #XXXX
refs: endojs/endo#2042

## Description

Starting at endojs/endo#2042 endo fully supports
the real `AggregateError` constructor, so there is no longer any need
for the `makeAggregateError` workaround. The @agoric/internal packages
*should* not be imported by anything outside the agoric-sdk repo, so
technically I could remove it in this same PR. As a conservative
don't-break-things, I still export it as deprecated.

Even after upgrading to an endo supporting `AggregateError`, the old
`makeAggregateError` was emulating it using a direct instance of
`Error`, so this is in theory not a pure refactor. But I would be
flabbergasted if any code came to depend on this not being a genuine
`AggregateError`, in which case this change is a pure refactor.

Reviewers, please let me know if you'd prefer that I delete
`makeAggregateError`, as I'd be happy to.

### Security Considerations
none

### Scaling Considerations

none
### Documentation Considerations

none
### Testing Considerations

none
### Upgrade Considerations

none

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
erights and mergify[bot] authored Apr 22, 2024
1 parent 84de950 commit c0e811e
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 28 deletions.
3 changes: 0 additions & 3 deletions packages/agoric-cli/src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,6 @@ export default async function installMain(progname, rawArgs, powers, opts) {
({ status }) => status !== 'fulfilled',
);
if (failures.length) {
if (typeof AggregateError !== 'function') {
throw failures[0].reason;
}
throw AggregateError(
failures.map(({ reason }) => reason),
'Failed to prune',
Expand Down
3 changes: 1 addition & 2 deletions packages/cosmic-swingset/src/export-kernel-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { fileURLToPath } from 'url';

import { makePromiseKit } from '@endo/promise-kit';
import { Fail, q } from '@agoric/assert';
import { makeAggregateError } from '@agoric/internal';
import { makeShutdown } from '@agoric/internal/src/node/shutdown.js';
import { makeSwingStoreExporter } from '@agoric/swing-store';

Expand Down Expand Up @@ -239,7 +238,7 @@ export const initiateSwingStoreExport = (
.catch(err => errors.push(err));
}
if (errors.length) {
const error = makeAggregateError(errors, 'Errors while cleaning up');
const error = AggregateError(errors, 'Errors while cleaning up');
if (opErr) {
Object.defineProperty(error, 'cause', { value: opErr });
}
Expand Down
3 changes: 1 addition & 2 deletions packages/internal/src/node/fs-stream.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createWriteStream } from 'node:fs';
import { open } from 'node:fs/promises';
import { makeAggregateError } from '../utils.js';

/**
* @param {import("fs").ReadStream | import("fs").WriteStream} stream
Expand Down Expand Up @@ -78,7 +77,7 @@ export const makeFsStreamWriter = async filePath => {
Promise.reject(
written.then(
() => err,
writtenError => makeAggregateError([err, writtenError]),
writtenError => AggregateError([err, writtenError]),
),
),
);
Expand Down
21 changes: 2 additions & 19 deletions packages/internal/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,6 @@ export const makeMeasureSeconds = currentTimeMillisec => {
return measureSeconds;
};

/**
* @param {Error[]} errors
* @param {string} [message]
*/
export const makeAggregateError = (errors, message) => {
const err = Error(message);
Object.defineProperties(err, {
name: {
value: 'AggregateError',
},
errors: {
value: errors,
},
});
return err;
};

/**
* @template T
* @param {readonly (T | PromiseLike<T>)[]} items
Expand All @@ -101,7 +84,7 @@ export const PromiseAllOrErrors = async items => {
} else if (errors.length === 1) {
throw errors[0];
} else {
throw makeAggregateError(errors);
throw AggregateError(errors);
}
});
};
Expand All @@ -119,7 +102,7 @@ export const aggregateTryFinally = async (trier, finalizer) =>
finalizer(tryError)
.then(
() => tryError,
finalizeError => makeAggregateError([tryError, finalizeError]),
finalizeError => AggregateError([tryError, finalizeError]),
)
.then(error => Promise.reject(error)),
);
Expand Down
3 changes: 1 addition & 2 deletions packages/telemetry/src/slog-sender-pipe-entrypoint.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* global process */
import '@endo/init';

import { makeAggregateError } from '@agoric/internal';
import anylogger from 'anylogger';
import { makeShutdown } from '@agoric/internal/src/node/shutdown.js';

Expand Down Expand Up @@ -75,7 +74,7 @@ const main = async () => {
sendErrors.unshift(actualFlushError);
}

return makeAggregateError(sendErrors.splice(0));
return AggregateError(sendErrors.splice(0));
};

process.on(
Expand Down

0 comments on commit c0e811e

Please sign in to comment.