-
Notifications
You must be signed in to change notification settings - Fork 109
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
How to correctly capture DockerException? #564
Comments
Well, this is tricky, and definitly an area where Python-on-whales could be improved. To enable TTY by default, we must avoid capturing any output. This is because the docker client can detect if stdout and stderr are TTY and changes the output accordingly. You can disable TTY, but it's still not captured from the python side at the moment. You could try contextlib.redirect_stdout and contextlib.redirect_stderr with The right solution would be to make the subprocess believe it's using a TTY while we grab the output, with something like https://docs.python.org/fr/3/library/pty.html for example, but that's a lot of work, and may not be a good fit for this simple codebase. You can try to experiment with |
I see. We will experiment with As a first quick and dirty way to do it (which works for our use case, but doesn't address the issues you mentioned above):
It captures indeed error messages as expected. However, as |
Indeed I wish they would return different error codes depending on the error type, then we wouldn't have to parse logs to see what kind of error it was. I raised an issue a while ago but it didn't get much traction. |
I am not sure to understand how to correctly capture the errors of some
python-on-whales
calls.A specific example:
The
docker-compose.yml
contains an error (in this case an external network is missing). The output I get is this:The error I am interested in catching is
Error response from daemon: network factory-net not found
.How would I do this?
A
try
except
clause doesn't seem to work here.which results in
The error message I am interested in can't be find in the raised
DockerException
as neitherstdout
norstderr
were captured (they both returnNone
). I guess the messageError response from daemon: network factory-net not found
should be either instdout
orstderr
.Do I have to configure somehow my
DockerClient
in order thestdout
andstderr
get captured? Or how do I access the error response from the Docker daemon?The text was updated successfully, but these errors were encountered: