Throw typed errors with a `cause`

Ouverte
#1,532 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 4 jours

Personne n'a encore pris cette issue.

Évaluation

Difficulté
5/5
Temps estimé
Plus d'une semaine
Accessibilité débutants
42/100
Type d'issue
Fonctionnalité
Clarté
Plutôt claire
Activité
Active
Stack technique
docker, node.js, typescript
Domaine
backend, testing

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.
Langage dominant
TypeScript
Étoiles
2.7k
Forks
290
Merge moyen
4 j 1 h
PR mergées (30 j)
22

Préparer son environnement

Ouvrir dans Codespaces

Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de testcontainers/testcontainers-node

Toutes les issues de testcontainers/testcontainers-node

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.