]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
fix(conninfo): improve error message when host resolution fails
authordeeshantk <deeshantkotnala@gmail.com>
Sat, 8 Nov 2025 15:52:45 +0000 (21:22 +0530)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 16 Nov 2025 15:20:26 +0000 (16:20 +0100)
psycopg/psycopg/_conninfo_attempts.py
psycopg/psycopg/_conninfo_attempts_async.py

index f853e0537c502511eb6baa74901090765c1c0466..b619ae78e439f264356110e8fc54ec68fb9e12dd 100644 (file)
@@ -44,13 +44,15 @@ def conninfo_attempts(params: ConnMapping) -> list[ConnDict]:
         try:
             attempts.extend(_resolve_hostnames(attempt))
         except OSError as ex:
-            logger.debug("failed to resolve host %r: %s", attempt.get("host"), ex)
-            last_exc = ex
+            last_exc = e.OperationalError(
+                f"failed to resolve host {attempt.get('host')!r}: {ex}"
+            )
+            logger.debug("%s", last_exc)
 
     if not attempts:
         assert last_exc
         # We couldn't resolve anything
-        raise e.OperationalError(str(last_exc))
+        raise last_exc
 
     if get_param(params, "load_balance_hosts") == "random":
         shuffle(attempts)
index 08f363d1ac7235ee5dcd5ca6658979d708135a3e..21228b4d46b4a97a16c3915708d3e3f97e709c1a 100644 (file)
@@ -42,13 +42,15 @@ async def conninfo_attempts_async(params: ConnMapping) -> list[ConnDict]:
         try:
             attempts.extend(await _resolve_hostnames(attempt))
         except OSError as ex:
-            logger.debug("failed to resolve host %r: %s", attempt.get("host"), ex)
-            last_exc = ex
+            last_exc = e.OperationalError(
+                f"failed to resolve host {attempt.get('host')!r}: {ex}"
+            )
+            logger.debug("%s", last_exc)
 
     if not attempts:
         assert last_exc
         # We couldn't resolve anything
-        raise e.OperationalError(str(last_exc))
+        raise last_exc
 
     if get_param(params, "load_balance_hosts") == "random":
         shuffle(attempts)