Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Split error handling helpers for promise utils #30195

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions lib/util/promises.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,11 @@ function isExternalHostError(err: any): err is ExternalHostError {
return err instanceof ExternalHostError;
}

function handleError(err: any): never {
if (!(err instanceof AggregateError)) {
throw err;
}

logger.debug({ err }, 'Aggregate error is thrown');

const errors = [...err];

function handleMultipleErrors(errors: Error[]): never {
const hostError = errors.find(isExternalHostError);
if (hostError) {
throw hostError;
}

if (
errors.length === 1 ||
new Set(errors.map(({ message }) => message)).size === 1
Expand All @@ -32,7 +23,16 @@ function handleError(err: any): never {
throw error;
}

throw err;
throw new AggregateError(errors);
}

function handleError(err: any): never {
if (!(err instanceof AggregateError)) {
throw err;
}

logger.debug({ err }, 'Aggregate error is thrown');
handleMultipleErrors([...err]);
}

export async function all<T>(
Expand Down