Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw the new DockerUnavailableException when Docker is not available #1308

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

0xced
Copy link
Contributor

@0xced 0xced commented Nov 26, 2024

What does this PR do?

This pull request introduces a new DockerUnavailableException which is thrown instead of ArgumentException which was not the appropriate exception to throw since the root of the problem is not a bad argument but the state of the system which is wrong.

The exception message has also been slightly improved.

Why is it important?

Unlike ArgumentException, DockerUnavailableException can be caught handled.

Related issues

Once both this pull request and #1263 are merged, the error messages will be improved, giving a better hint to the user at what went wrong. Here are two sample messages from the new DockerUnavailableException.

Running Testcontainers after quitting Docker Desktop:

Docker is either not running or misconfigured. Please ensure that Docker is available at unix:///var/run/docker.sock or unix:///Users/0xced/.docker/run/docker.sock
You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit:
https://dotnet.testcontainers.org/custom_configuration/

Running Testcontainers after quitting OrbStack:

Docker is either not running or misconfigured. Please ensure that Docker is available at unix:///var/run/docker.sock or unix:///Users/0xced/.orbstack/run/docker.sock
You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit:
https://dotnet.testcontainers.org/custom_configuration/

How to test this PR

Quit Docker Desktop or configure a bad endpoint then try to run a container. Observe the improved exception and error message.

Copy link

netlify bot commented Nov 26, 2024

Deploy Preview for testcontainers-dotnet ready!

Name Link
🔨 Latest commit 72e96c1
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-dotnet/deploys/676573a5710fa60008ce10fd
😎 Deploy Preview https://deploy-preview-1308--testcontainers-dotnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Collaborator

@HofmeisterAn HofmeisterAn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should discuss this in an issue. We can merge the PR, but I think these features would be better in Docker.DotNet. Things like detecting the container runtime, getting private registry credentials, etc. should be part of Docker.DotNet where more developers benefit from. This is one reason why we forked Docker.DotNet and use our own implementation. The Java's client has way more features and is much more developer-friendly than our .NET counterpart.

(because it is either not running or misconfigured)

The `ArgumentException` was not the appropriate exception to throw since the root of the problem is not a bad argument but the state of the system which is wrong.
@0xced 0xced force-pushed the DockerUnavailableException branch from 9fccae7 to 72e96c1 Compare December 20, 2024 13:39
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.

2 participants