Throw typed errors with a `cause`

Aperta
#1,532 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 4 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
42/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
docker, node.js, typescript
Ambito
backend, testing

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.
Lingua principale
TypeScript
Stelle
2.7k
Fork
290
Merge medio
4g 1h
PR unite (30g)
22

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di testcontainers/testcontainers-node

Tutte le issue di testcontainers/testcontainers-node

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.