summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Schöchlin <ms-github@256bit.org>2023-04-27 16:18:09 +0200
committerGitHub <noreply@github.com>2023-04-27 17:18:09 +0300
commit8e0b84d8a25c90070817c911af266cd5cabe1604 (patch)
tree5383b8e6d827e6d8d67251f97ca7aa8ba89330ac
parentfddd3d6b306724988249d117cd9e405ac78ffecc (diff)
downloadredis-py-8e0b84d8a25c90070817c911af266cd5cabe1604.tar.gz
Improve error output for master discovery (#2720)
Make MasterNotFoundError exception more precise in the case of ConnectionError and TimeoutError to help the user to identify configuration errors Co-authored-by: Marc Schöchlin <marc.schoechlin@flipapp.de>
-rw-r--r--CHANGES1
-rw-r--r--redis/asyncio/sentinel.py10
-rw-r--r--redis/sentinel.py10
3 files changed, 17 insertions, 4 deletions
diff --git a/CHANGES b/CHANGES
index d1e4b2a..8c6100d 100644
--- a/CHANGES
+++ b/CHANGES
@@ -42,6 +42,7 @@
* Fix Sentinel.execute_command doesn't execute across the entire sentinel cluster bug (#2458)
* Added a replacement for the default cluster node in the event of failure (#2463)
* Fix for Unhandled exception related to self.host with unix socket (#2496)
+ * Improve error output for master discovery
* 4.1.3 (Feb 8, 2022)
* Fix flushdb and flushall (#1926)
diff --git a/redis/asyncio/sentinel.py b/redis/asyncio/sentinel.py
index c3c0f91..9147ed8 100644
--- a/redis/asyncio/sentinel.py
+++ b/redis/asyncio/sentinel.py
@@ -254,10 +254,12 @@ class Sentinel(AsyncSentinelCommands):
Returns a pair (address, port) or raises MasterNotFoundError if no
master is found.
"""
+ collected_errors = list()
for sentinel_no, sentinel in enumerate(self.sentinels):
try:
masters = await sentinel.sentinel_masters()
- except (ConnectionError, TimeoutError):
+ except (ConnectionError, TimeoutError) as e:
+ collected_errors.append(f"{sentinel} - {e!r}")
continue
state = masters.get(service_name)
if state and self.check_master_state(state, service_name):
@@ -267,7 +269,11 @@ class Sentinel(AsyncSentinelCommands):
self.sentinels[0],
)
return state["ip"], state["port"]
- raise MasterNotFoundError(f"No master found for {service_name!r}")
+
+ error_info = ""
+ if len(collected_errors) > 0:
+ error_info = f" : {', '.join(collected_errors)}"
+ raise MasterNotFoundError(f"No master found for {service_name!r}{error_info}")
def filter_slaves(
self, slaves: Iterable[Mapping]
diff --git a/redis/sentinel.py b/redis/sentinel.py
index d70b714..ac6921a 100644
--- a/redis/sentinel.py
+++ b/redis/sentinel.py
@@ -230,10 +230,12 @@ class Sentinel(SentinelCommands):
Returns a pair (address, port) or raises MasterNotFoundError if no
master is found.
"""
+ collected_errors = list()
for sentinel_no, sentinel in enumerate(self.sentinels):
try:
masters = sentinel.sentinel_masters()
- except (ConnectionError, TimeoutError):
+ except (ConnectionError, TimeoutError) as e:
+ collected_errors.append(f"{sentinel} - {e!r}")
continue
state = masters.get(service_name)
if state and self.check_master_state(state, service_name):
@@ -243,7 +245,11 @@ class Sentinel(SentinelCommands):
self.sentinels[0],
)
return state["ip"], state["port"]
- raise MasterNotFoundError(f"No master found for {service_name!r}")
+
+ error_info = ""
+ if len(collected_errors) > 0:
+ error_info = f" : {', '.join(collected_errors)}"
+ raise MasterNotFoundError(f"No master found for {service_name!r}{error_info}")
def filter_slaves(self, slaves):
"Remove slaves that are in an ODOWN or SDOWN state"