Skip to content

Commit

Permalink
Catch BaseException instead of Exception
Browse files Browse the repository at this point in the history
- Exception does not include KeyboardInterrupt or CancelledError
- closes #619
- closes #639
  • Loading branch information
aleneum committed Oct 24, 2023
1 parent 8ab2529 commit 93e7f20
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions transitions/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def _trigger(self, event_data):
try:
if self._is_valid_source(event_data.state):
self._process(event_data)
except Exception as err: # pylint: disable=broad-except; Exception will be handled elsewhere
except BaseException as err: # pylint: disable=broad-except; Exception will be handled elsewhere
event_data.error = err
if self.machine.on_exception:
self.machine.callbacks(self.machine.on_exception, event_data)
Expand All @@ -424,7 +424,7 @@ def _trigger(self, event_data):
try:
self.machine.callbacks(self.machine.finalize_event, event_data)
_LOGGER.debug("%sExecuted machine finalize callbacks", self.machine.name)
except Exception as err: # pylint: disable=broad-except; Exception will be handled elsewhere
except BaseException as err: # pylint: disable=broad-except; Exception will be handled elsewhere
_LOGGER.error("%sWhile executing finalize callbacks a %s occurred: %s.",
self.machine.name,
type(err).__name__,
Expand Down Expand Up @@ -1224,7 +1224,7 @@ def _process(self, trigger):
try:
self._transition_queue[0]()
self._transition_queue.popleft()
except Exception:
except BaseException:
# if a transition raises an exception, clear queue and delegate exception handling
self._transition_queue.clear()
raise
Expand Down
8 changes: 4 additions & 4 deletions transitions/extensions/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ async def _trigger(self, event_data):
try:
if self._is_valid_source(event_data.state):
await self._process(event_data)
except Exception as err: # pylint: disable=broad-except; Exception will be handled elsewhere
except BaseException as err: # pylint: disable=broad-except; Exception will be handled elsewhere
_LOGGER.error("%sException was raised while processing the trigger: %s", self.machine.name, err)
event_data.error = err
if self.machine.on_exception:
Expand Down Expand Up @@ -455,7 +455,7 @@ async def _process_async(self, trigger, model):
while self._transition_queue_dict[id(model)]:
try:
await self._transition_queue_dict[id(model)][0]()
except Exception:
except BaseException:
# if a transition raises an exception, clear queue and delegate exception handling
self._transition_queue_dict[id(model)].clear()
raise
Expand Down Expand Up @@ -503,7 +503,7 @@ async def _trigger_event(self, event_data, trigger):
with self():
res = await self._trigger_event_nested(event_data, trigger, None)
event_data.result = self._check_event_result(res, event_data.model, trigger)
except Exception as err: # pylint: disable=broad-except; Exception will be handled elsewhere
except BaseException as err: # pylint: disable=broad-except; Exception will be handled elsewhere
event_data.error = err
if self.on_exception:
await self.callbacks(self.on_exception, event_data)
Expand All @@ -513,7 +513,7 @@ async def _trigger_event(self, event_data, trigger):
try:
await self.callbacks(self.finalize_event, event_data)
_LOGGER.debug("%sExecuted machine finalize callbacks", self.name)
except Exception as err: # pylint: disable=broad-except; Exception will be handled elsewhere
except BaseException as err: # pylint: disable=broad-except; Exception will be handled elsewhere
_LOGGER.error("%sWhile executing finalize callbacks a %s occurred: %s.",
self.name,
type(err).__name__,
Expand Down
4 changes: 2 additions & 2 deletions transitions/extensions/nesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ def _trigger_event(self, event_data, trigger):
with self():
res = self._trigger_event_nested(event_data, trigger, None)
event_data.result = self._check_event_result(res, event_data.model, trigger)
except Exception as err: # pylint: disable=broad-except; Exception will be handled elsewhere
except BaseException as err: # pylint: disable=broad-except; Exception will be handled elsewhere
event_data.error = err
if self.on_exception:
self.callbacks(self.on_exception, event_data)
Expand All @@ -822,7 +822,7 @@ def _trigger_event(self, event_data, trigger):
try:
self.callbacks(self.finalize_event, event_data)
_LOGGER.debug("%sExecuted machine finalize callbacks", self.name)
except Exception as err: # pylint: disable=broad-except; Exception will be handled elsewhere
except BaseException as err: # pylint: disable=broad-except; Exception will be handled elsewhere
_LOGGER.error("%sWhile executing finalize callbacks a %s occurred: %s.",
self.name,
type(err).__name__,
Expand Down

0 comments on commit 93e7f20

Please sign in to comment.