Skip to content

Commit

Permalink
refactor: remove string interpolation in favour of exception chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
a-ungurianu committed Nov 16, 2022
1 parent 5851e40 commit e38b5c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions kazoo/protocol/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,11 +806,11 @@ def _authenticate_with_sasl(self, host, timeout):
try:
response = sasl_cli.process(challenge=challenge)
except puresasl.SASLError as err:
raise SASLException("library error: %s" % err) from err
except puresasl.SASLProtocolException as err:
raise AuthFailedError("protocol error: %s" % err) from err
except Exception as err:
raise AuthFailedError("Unknown error: %s" % err) from err
raise SASLException("library error") from err
except puresasl.SASLProtocolException as exc:
raise AuthFailedError("protocol error") from exc
except Exception as exc:
raise AuthFailedError("Unknown error") from exc

if sasl_cli.complete and not response:
break
Expand All @@ -824,9 +824,9 @@ def _authenticate_with_sasl(self, host, timeout):

try:
header, buffer, offset = self._read_header(timeout)
except ConnectionDropped as ex:
except ConnectionDropped as exc:
# Zookeeper simply drops connections with failed authentication
raise AuthFailedError("Connection dropped in SASL") from ex
raise AuthFailedError("Connection dropped in SASL") from exc

if header.xid != xid:
raise RuntimeError(
Expand Down
4 changes: 2 additions & 2 deletions kazoo/recipe/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,12 @@ def acquire(self, blocking=True, timeout=None, ephemeral=True):
)
except RetryFailedError:
pass
except KazooException as ex:
except KazooException:
# if we did ultimately fail, attempt to clean up
if not already_acquired:
self._best_effort_cleanup()
self.cancelled = False
raise ex
raise
if gotten:
self.is_acquired = gotten
if not gotten and not already_acquired:
Expand Down

0 comments on commit e38b5c5

Please sign in to comment.