-
Notifications
You must be signed in to change notification settings - Fork 97
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
fix: Enhance environment connection error handling #472
base: main
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Mr-Sunglasses The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Signed-off-by: Kanishk Pachauri <[email protected]>
Signed-off-by: Kanishk Pachauri <[email protected]>
21d776c
to
19da087
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to test these exceptions if possible.
I'll give you an idea of what I was thinking to test it.
What do you think? :)
--- a/podman/tests/integration/test_system.py
+++ b/podman/tests/integration/test_system.py
@@ -64,3 +64,10 @@ class SystemIntegrationTest(base.IntegrationTest):
def test_from_env(self):
"""integration: from_env() no error"""
PodmanClient.from_env()
+
+ def test_from_env_exceptions(self):
+ """integration: from_env() returns exceptions"""
+ with self.assertRaises(PodmanConnectionError):
+ PodmanClient.from_env(base_url="unix:///path/to/nonexistent.sock")
except Exception as exc: | ||
error_msg = "Failed to initialize Podman client from environment" | ||
if isinstance(exc, ValueError): | ||
error_msg = "Invalid environment configuration for Podman client" | ||
elif isinstance(exc, (ConnectionError, TimeoutError)): | ||
error_msg = "Failed to connect to Podman service" | ||
|
||
raise PodmanConnectionError( | ||
message=error_msg, environment=environment, host=host, original_error=exc | ||
) from exc | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For code clarity, I would prefer to use python's exception handling here.
except ValueError as e:
error_msg = "Invalid environment configuration for Podman client"
raise PodmanConnectionError(
message=error_msg, environment=environment, host=host, original_error=e)
except (ConnectionError, TimeoutError) as e:
error_msg = "Failed to connect to Podman service"
raise PodmanConnectionError(
message=error_msg, environment=environment, host=host, original_error=e)
except Exception as e:
error_msg = "Failed to initialize Podman client from environment"
raise PodmanConnectionError(
message=error_msg, environment=environment, host=host, original_error=e)
I would avoid filtering exceptions with if conditions in the except block, unless you have a strong reason to do so.
fix: #455
Add
PodmanConnectionError
to improve debugging of connection failures wheninitializing client from environment variables. The new error provides:
Previously, raw exceptions from connection attempts could be confusing to
diagnose, especially when involving environment variables. This change makes it
clearer what went wrong during client initialization.