Skip to content

Commit 9029d23

Browse files
committed
unmask dns error
1 parent ff83d01 commit 9029d23

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

pymongo/asynchronous/srv_resolver.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ def __init__(
9393
try:
9494
split_fqdn = self.__fqdn.split(".")
9595
self.__plist = split_fqdn[1:] if len(split_fqdn) > 2 else split_fqdn
96-
except Exception:
97-
raise ConfigurationError(_INVALID_HOST_MSG % (fqdn,)) from None
96+
except Exception as exc:
97+
raise ConfigurationError(_INVALID_HOST_MSG % (fqdn,)) from exc
9898
self.__slen = len(self.__plist)
9999
self.nparts = len(split_fqdn)
100100

@@ -107,7 +107,7 @@ async def get_options(self) -> Optional[str]:
107107
# No TXT records
108108
return None
109109
except Exception as exc:
110-
raise ConfigurationError(str(exc)) from None
110+
raise ConfigurationError(str(exc)) from exc
111111
if len(results) > 1:
112112
raise ConfigurationError("Only one TXT record is supported")
113113
return (b"&".join([b"".join(res.strings) for res in results])).decode("utf-8") # type: ignore[attr-defined]
@@ -122,8 +122,7 @@ async def _resolve_uri(self, encapsulate_errors: bool) -> resolver.Answer:
122122
# Raise the original error.
123123
raise
124124
# Else, raise all errors as ConfigurationError.
125-
raise ValueError(f"{self.__srv=} {self.__fqdn=} {exc=}") from None
126-
raise ConfigurationError(str(exc)) from None
125+
raise ConfigurationError(str(exc)) from exc
127126
return results
128127

129128
async def _get_srv_response_and_hosts(
@@ -146,8 +145,8 @@ async def _get_srv_response_and_hosts(
146145
)
147146
try:
148147
nlist = srv_host.split(".")[1:][-self.__slen :]
149-
except Exception:
150-
raise ConfigurationError(f"Invalid SRV host: {node[0]}") from None
148+
except Exception as exc:
149+
raise ConfigurationError(f"Invalid SRV host: {node[0]}") from exc
151150
if self.__plist != nlist:
152151
raise ConfigurationError(f"Invalid SRV host: {node[0]}")
153152
if self.__srv_max_hosts:

pymongo/synchronous/srv_resolver.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ def __init__(
9393
try:
9494
split_fqdn = self.__fqdn.split(".")
9595
self.__plist = split_fqdn[1:] if len(split_fqdn) > 2 else split_fqdn
96-
except Exception:
97-
raise ConfigurationError(_INVALID_HOST_MSG % (fqdn,)) from None
96+
except Exception as exc:
97+
raise ConfigurationError(_INVALID_HOST_MSG % (fqdn,)) from exc
9898
self.__slen = len(self.__plist)
9999
self.nparts = len(split_fqdn)
100100

@@ -107,7 +107,7 @@ def get_options(self) -> Optional[str]:
107107
# No TXT records
108108
return None
109109
except Exception as exc:
110-
raise ConfigurationError(str(exc)) from None
110+
raise ConfigurationError(str(exc)) from exc
111111
if len(results) > 1:
112112
raise ConfigurationError("Only one TXT record is supported")
113113
return (b"&".join([b"".join(res.strings) for res in results])).decode("utf-8") # type: ignore[attr-defined]
@@ -122,8 +122,7 @@ def _resolve_uri(self, encapsulate_errors: bool) -> resolver.Answer:
122122
# Raise the original error.
123123
raise
124124
# Else, raise all errors as ConfigurationError.
125-
raise ValueError(f"{self.__srv=} {self.__fqdn=} {exc=}") from None
126-
raise ConfigurationError(str(exc)) from None
125+
raise ConfigurationError(str(exc)) from exc
127126
return results
128127

129128
def _get_srv_response_and_hosts(
@@ -146,8 +145,8 @@ def _get_srv_response_and_hosts(
146145
)
147146
try:
148147
nlist = srv_host.split(".")[1:][-self.__slen :]
149-
except Exception:
150-
raise ConfigurationError(f"Invalid SRV host: {node[0]}") from None
148+
except Exception as exc:
149+
raise ConfigurationError(f"Invalid SRV host: {node[0]}") from exc
151150
if self.__plist != nlist:
152151
raise ConfigurationError(f"Invalid SRV host: {node[0]}")
153152
if self.__srv_max_hosts:

0 commit comments

Comments
 (0)