Skip to content

Commit 4698155

Browse files
committed
Add error/host details to OperationTimedOut
1 parent ec95133 commit 4698155

3 files changed

Lines changed: 23 additions & 6 deletions

File tree

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Other
1919
* Skip sending OPTIONS message on connection creation if compression is
2020
disabled or not available and a CQL version has not been explicitly
2121
set
22+
* Add details about errors and the last queried host to ``OperationTimedOut``
2223

2324
1.0.0 Final
2425
===========

cassandra/__init__.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,19 @@ class OperationTimedOut(Exception):
226226
to complete. This is not an error generated by Cassandra, only
227227
the driver.
228228
"""
229-
pass
229+
230+
errors = None
231+
"""
232+
A dict of errors keyed by the :class:`~.Host` against which they occurred.
233+
"""
234+
235+
last_host = None
236+
"""
237+
The last :class:`~.Host` this operation was attempted against.
238+
"""
239+
240+
def __init__(self, errors=None, last_host=None):
241+
self.errors = errors
242+
self.last_host = last_host
243+
message = "errors=%s, last_host=%s" % (self.errors, self.last_host)
244+
Exception.__init__(self, message)

cassandra/cluster.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -852,8 +852,8 @@ def _prepare_all_queries(self, host):
852852
"statement on host %s: %r", host, response)
853853

854854
log.debug("Done preparing all known prepared statements against host %s", host)
855-
except OperationTimedOut:
856-
log.warn("Timed out trying to prepare all statements on host %s", host)
855+
except OperationTimedOut as timeout:
856+
log.warn("Timed out trying to prepare all statements on host %s: %s", host, timeout)
857857
except (ConnectionException, socket.error) as exc:
858858
log.warn("Error trying to prepare all statements on host %s: %r", host, exc)
859859
except Exception:
@@ -1644,8 +1644,9 @@ def wait_for_schema_agreement(self, connection=None):
16441644
timeout = min(2.0, total_timeout - elapsed)
16451645
peers_result, local_result = connection.wait_for_responses(
16461646
peers_query, local_query, timeout=timeout)
1647-
except OperationTimedOut:
1648-
log.debug("[control connection] Timed out waiting for response during schema agreement check")
1647+
except OperationTimedOut as timeout:
1648+
log.debug("[control connection] Timed out waiting for " \
1649+
"response during schema agreement check: %s", timeout)
16491650
elapsed = self._time.time() - start
16501651
continue
16511652

@@ -2189,7 +2190,7 @@ def result(self, timeout=_NOT_SET):
21892190
elif self._final_exception:
21902191
raise self._final_exception
21912192
else:
2192-
raise OperationTimedOut()
2193+
raise OperationTimedOut(errors=self._errors, last_host=self._current_host)
21932194

21942195
def get_query_trace(self, max_wait=None):
21952196
"""

0 commit comments

Comments
 (0)