Skip to content

Say why no container runtime was found - #1621

Open
tahmidbintaslim wants to merge 1 commit into
testcontainers:mainfrom
tahmidbintaslim:explain-no-container-runtime
Open

tahmidbintaslim wants to merge 1 commit into
testcontainers:mainfrom
tahmidbintaslim:explain-no-container-runtime

Conversation

@tahmidbintaslim

Copy link
Copy Markdown

Closes #1571

Summary

When no container runtime works, the error now lists every strategy that was tried and why it was skipped or failed, then links to the supported runtimes docs. For example, on Linux where the socket exists but isn't readable:

Could not find a working container runtime strategy. Tried:
  - TestcontainersHostStrategy: not applicable: tc.host is not set in ~/.testcontainers.properties
  - ConfigurationStrategy: not applicable: DOCKER_HOST is not set in the environment or ~/.testcontainers.properties
  - UnixSocketStrategy: failed: connect EACCES /var/run/docker.sock
  - RootlessUnixSocketStrategy: not applicable: no socket found at /run/user/1000/docker.sock, ...
  - NpipeSocketStrategy: not applicable: only used on Windows
See https://node.testcontainers.org/supported-container-runtimes/

Strategies used to return undefined for "not applicable". They now return { notApplicable: reason }. Errors from strategies that applied but failed are attached as cause, wrapped in an AggregateError. The first line of the message is unchanged, so anything matching on it keeps working. I kept this a plain Error so it can move onto the typed errors from #1532 without conflict.

Verification

  • Red: on main, the 7 new "should not apply" strategy tests fail (they get undefined instead of a reason).
  • Green: npx vitest run packages/testcontainers/src/container-runtime/strategies packages/testcontainers/src/container-runtime/clients/no-working-strategy-error.test.ts: 7 files, 30 tests passed.
  • npx biome check ., npm run knip and npm run check-compiles: pass.

Not breaking

The strategy classes aren't exported from index.ts, so their return type is internal. The error's first line is the same as before.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Say why no container runtime was found

1 participant