Throw typed errors with a `cause`

Offen
#1,532 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 4 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Anfängerfreundlichkeit
42/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
docker, node.js, typescript
Bereich
backend, testing

Rechercherichtung

Start by reading the listed wait-strategy, generic-container, bound-ports, and docker-compose-environment files, then trace the 33 new Error(...) sites and existing tests. Define exported error categories with useful fields and preserve existing messages while attaching underlying errors as cause. Done when the main listed failure types are distinguishable by class, retain causes where errors are wrapped, and tests cover the new fields and unchanged messages.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

enhancement minor

What happens

Every error created by packages/testcontainers is a plain Error. There are 33 new Error(...) sites and no error subclasses. A caller can only tell failures apart by matching message text:

  • Log message "..." not received after 60000ms
  • URL /health not accessible after 60000ms
  • Image "..." does not exist locally and pull policy is "never"
  • No port binding found for :8080/tcp
  • Cannot get container "..." as it is not running
  • Failed to build image

None of them carry a cause, so the underlying Docker or network error is lost when one is wrapped.

Expected

Exported error classes for the main failure categories, with useful fields, so callers and test helpers can branch on them:

  • startup timeout (strategy, timeout, container id)
  • container exited during startup (exit code)
  • image pull or build failure
  • missing port binding or unknown container

Underlying errors are attached as cause.

Where

  • packages/testcontainers/src/wait-strategies/*.ts
  • packages/testcontainers/src/generic-container/*.ts
  • packages/testcontainers/src/utils/bound-ports.ts
  • packages/testcontainers/src/docker-compose-environment/*.ts

Notes

  • Java has ContainerLaunchException and ContainerFetchException.
  • Related: #1506 (container logs in the start error), #1507 (fail the HTTP wait when the container exits), #1508 (build output on a failed build). Typed errors give those a place to put the logs and exit code.
  • Keeping the existing messages makes this additive.

Dependencies

  • Nothing blocks this. It can start now.
Vorherrschende Sprache
TypeScript
Sterne
2.7k
Forks
290
Ø Merge
4 T. 1 Std.
Gemergte PRs (30 T.)
22

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus testcontainers/testcontainers-node

Alle Issues in testcontainers/testcontainers-node

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.