Skip to content

Commit bc2584d

Browse files
committed
stopping wrapping of driver exceptions as is maintenance issue
1 parent e529e30 commit bc2584d

File tree

1 file changed

+101
-7
lines changed

1 file changed

+101
-7
lines changed

src/async_cassandra/session.py

Lines changed: 101 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,25 @@
1010
import time
1111
from typing import Any, Dict, Optional
1212

13-
from cassandra import DriverException
13+
from cassandra import (
14+
AlreadyExists,
15+
AuthenticationFailed,
16+
CDCWriteFailure,
17+
CoordinationFailure,
18+
FunctionFailure,
19+
InvalidRequest,
20+
OperationTimedOut,
21+
ReadFailure,
22+
ReadTimeout,
23+
Unauthorized,
24+
Unavailable,
25+
UnsupportedOperation,
26+
WriteFailure,
27+
WriteTimeout,
28+
)
1429
from cassandra.cluster import _NOT_SET, EXEC_PROFILE_DEFAULT, Cluster, NoHostAvailable, Session
30+
from cassandra.connection import ConnectionBusy, ConnectionShutdown, ProtocolError
31+
from cassandra.pool import NoConnectionsAvailable
1532
from cassandra.protocol import ErrorMessage
1633
from cassandra.query import BatchStatement, PreparedStatement, SimpleStatement
1734

@@ -177,13 +194,37 @@ async def execute(
177194
return result
178195

179196
except (
180-
DriverException, # Base class for all Cassandra driver exceptions
197+
# These exceptions should NOT be wrapped - pass through as-is
198+
ReadTimeout,
199+
WriteTimeout,
200+
OperationTimedOut,
201+
Unavailable,
202+
InvalidRequest,
203+
AlreadyExists,
204+
Unauthorized,
205+
AuthenticationFailed,
181206
ErrorMessage, # Base class for protocol-level errors like SyntaxException
182207
NoHostAvailable, # Not a DriverException but should pass through
183208
) as e:
184-
# Re-raise Cassandra exceptions without wrapping
209+
# Re-raise these specific Cassandra exceptions without wrapping
185210
error_type = type(e).__name__
186211
raise
212+
except (
213+
# These exceptions SHOULD be wrapped in QueryError
214+
UnsupportedOperation,
215+
ReadFailure,
216+
WriteFailure,
217+
FunctionFailure,
218+
CDCWriteFailure,
219+
CoordinationFailure,
220+
ProtocolError,
221+
ConnectionBusy,
222+
ConnectionShutdown,
223+
NoConnectionsAvailable,
224+
) as e:
225+
# Wrap these exceptions in QueryError
226+
error_type = type(e).__name__
227+
raise QueryError(f"Query execution failed: {str(e)}", cause=e) from e
187228
except asyncio.TimeoutError:
188229
# Re-raise timeout errors without wrapping
189230
error_type = "TimeoutError"
@@ -290,12 +331,40 @@ async def execute_stream(
290331
return result
291332

292333
except (
293-
DriverException, # Base class for all Cassandra driver exceptions
334+
# These exceptions should NOT be wrapped - pass through as-is
335+
ReadTimeout,
336+
WriteTimeout,
337+
OperationTimedOut,
338+
Unavailable,
339+
InvalidRequest,
340+
AlreadyExists,
341+
Unauthorized,
342+
AuthenticationFailed,
294343
ErrorMessage, # Base class for protocol-level errors like SyntaxException
295344
NoHostAvailable, # Not a DriverException but should pass through
296345
) as e:
297-
# Re-raise Cassandra exceptions without wrapping
346+
# Re-raise these specific Cassandra exceptions without wrapping
347+
error_type = type(e).__name__
348+
raise
349+
except (
350+
# These exceptions SHOULD be wrapped in QueryError
351+
UnsupportedOperation,
352+
ReadFailure,
353+
WriteFailure,
354+
FunctionFailure,
355+
CDCWriteFailure,
356+
CoordinationFailure,
357+
ProtocolError,
358+
ConnectionBusy,
359+
ConnectionShutdown,
360+
NoConnectionsAvailable,
361+
) as e:
362+
# Wrap these exceptions in QueryError
298363
error_type = type(e).__name__
364+
raise QueryError(f"Streaming query execution failed: {str(e)}", cause=e) from e
365+
except asyncio.TimeoutError:
366+
# Re-raise timeout errors without wrapping
367+
error_type = "TimeoutError"
299368
raise
300369
except Exception as e:
301370
# Only wrap non-Cassandra exceptions
@@ -395,9 +464,34 @@ async def prepare(
395464
return prepared
396465
except asyncio.TimeoutError:
397466
raise
398-
except (DriverException, ErrorMessage, NoHostAvailable):
399-
# Re-raise Cassandra exceptions without wrapping
467+
except (
468+
# These exceptions should NOT be wrapped - pass through as-is
469+
ReadTimeout,
470+
WriteTimeout,
471+
OperationTimedOut,
472+
Unavailable,
473+
InvalidRequest,
474+
AlreadyExists,
475+
ErrorMessage, # Base class for protocol-level errors like SyntaxException
476+
NoHostAvailable, # Not a DriverException but should pass through
477+
):
478+
# Re-raise these specific Cassandra exceptions without wrapping
400479
raise
480+
except (
481+
# These exceptions SHOULD be wrapped in QueryError
482+
UnsupportedOperation,
483+
ReadFailure,
484+
WriteFailure,
485+
FunctionFailure,
486+
CDCWriteFailure,
487+
CoordinationFailure,
488+
ProtocolError,
489+
ConnectionBusy,
490+
ConnectionShutdown,
491+
NoConnectionsAvailable,
492+
) as e:
493+
# Wrap these exceptions in QueryError
494+
raise QueryError(f"Statement preparation failed: {str(e)}", cause=e) from e
401495
except Exception as e:
402496
raise QueryError(f"Statement preparation failed: {str(e)}") from e
403497

0 commit comments

Comments
 (0)