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 and 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 160d1e4
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-dotnet/deploys/67bcc4782c365c00086f879d
😎 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.

@0xced 0xced force-pushed the DockerUnavailableException branch from 9fccae7 to 72e96c1 Compare December 20, 2024 13:39
@0xced
Copy link
Contributor Author

0xced commented Feb 15, 2025

but I think these features would be better in Docker.DotNet

Absolutely. Could be challenging, though!

@0xced 0xced force-pushed the DockerUnavailableException branch from 72e96c1 to 579d530 Compare February 17, 2025 08:48
@HofmeisterAn
Copy link
Collaborator

HofmeisterAn commented Feb 17, 2025

IIRC, we did not throw an exception on purpose because either one of the other providers may find a container runtime, or the user can set one explicitly via WithDockerEndpoint(string). If we want to have a more meaningful exception, why not simply throw it in Validate() and be done with it?

Edit: This comment was intended for: #1263. However, I now see that you are catching the exception here.

(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 579d530 to 160d1e4 Compare February 24, 2025 19:11
@0xced
Copy link
Contributor Author

0xced commented Feb 24, 2025

I've read your comment several times now, both in this context and in the context of #1263 but I still can't make sense of it. 😕

I mentioned #1263 in the original description of this pull request because by merging only this pull request, the error message would read like this:

Docker is either not running or misconfigured. Please ensure that Docker is available at unix:///var/run/docker.sock
You can customize […]

If merging both this pull request and #1263, the error message would read like this, hinting that running OrbStack is likely to solve the issue.

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 […]

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