Skip to content

Commit

Permalink
Use from clause when re-raising exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Cito committed Apr 29, 2023
1 parent 9923fc2 commit 9980bf5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions dbutils/persistent_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,11 @@ def connection(self, shareable=False): # noqa: ARG002
"""
try:
con = self.thread.connection
except AttributeError:
except AttributeError as error:
con = self.steady_connection()
if not con.threadsafety():
raise NotSupportedError("Database module is not thread-safe.")
raise NotSupportedError(
"Database module is not thread-safe.") from error
self.thread.connection = con
con._ping_check()
return con
Expand Down
9 changes: 5 additions & 4 deletions dbutils/steady_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,11 @@ def _create(self):
con.OperationalError,
con.InterfaceError,
con.InternalError)
except AttributeError:
except AttributeError as error:
raise AttributeError(
"Could not determine failure exceptions"
" (please set failures or creator.dbapi).")
" (please set failures or creator.dbapi)."
) from error
if isinstance(self._failures, tuple):
self._failure = self._failures[0]
else:
Expand Down Expand Up @@ -535,8 +536,8 @@ def __init__(self, con, *args, **kwargs):
self._clearsizes()
try:
self._cursor = con._cursor(*args, **kwargs)
except AttributeError:
raise TypeError(f"{con!r} is not a SteadyDBConnection.")
except AttributeError as error:
raise TypeError(f"{con!r} is not a SteadyDBConnection.") from error
self._closed = False

def __enter__(self):
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ select = [
]
# You can use `ruff rule ...` to see what these ignored rules check
ignore = [
"B904",
"E722",
"N811",
"N818",
Expand Down

0 comments on commit 9980bf5

Please sign in to comment.