< Summary - Envilder CLI

Information
Class: src/envilder/core/infrastructure/describeError.ts
Assembly: Default
File(s): src/envilder/core/infrastructure/describeError.ts
Tag: 427_29134414720
Line coverage
91%
Covered lines: 11
Uncovered lines: 1
Coverable lines: 12
Total lines: 28
Line coverage: 91.6%
Branch coverage
81%
Covered branches: 13
Total branches: 16
Branch coverage: 81.2%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

File(s)

src/envilder/core/infrastructure/describeError.ts

#LineLine coverage
 1/**
 2 * Extracts a human-readable reason from an unknown thrown value.
 3 *
 4 * Digs through `AggregateError.errors` and `Error.cause` so the reason is never
 5 * empty — the AWS SDK v3 wraps connection failures in an `AggregateError` whose
 6 * own `message` is empty and whose real causes live in `errors`.
 7 */
 8export function describeError(error: unknown): string {
 259  const reasons = [...new Set(collectReasons(error))];
 2510  return reasons.length > 0 ? reasons.join('; ') : 'unknown error';
 11}
 12
 13function collectReasons(error: unknown): string[] {
 3214  if (error instanceof AggregateError && error.errors.length > 0) {
 515    return error.errors.flatMap(collectReasons);
 16  }
 2717  if (error instanceof Error) {
 2218    if (error.message) {
 2119      return [error.message];
 20    }
 121    if (error.cause !== undefined) {
 122      return collectReasons(error.cause);
 23    }
 024    return error.name ? [error.name] : [];
 25  }
 526  const text = String(error);
 527  return text ? [text] : [];
 28}

Methods/Properties

describeError
collectReasons