Skip to content

Commit

Permalink
fix(main): clear cache when an unexpected error occurs (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
Toilal committed Jan 14, 2021
1 parent 9c396d5 commit 8c0940a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ddb/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,9 @@ def register_actions_in_event_bus(fail_fast=False):
_register_action_in_event_bus(action, event_binding, fail_fast)


def main(args: Optional[Sequence[str]] = None,
reset_disabled=False, before_handle_command_line=None):
def main(args: Optional[Sequence[str]] = None, # pylint:disable=too-many-statements
reset_disabled=False,
before_handle_command_line=None):
"""
Load all features and handle command line
"""
Expand Down Expand Up @@ -397,6 +398,13 @@ def on_config_reloaded():
return context.exceptions
except ExpectedError as exception:
return [exception]
except Exception as exception: # pylint:disable=broad-except
try:
clear_caches()
except Exception as clear_cache_exception: # pylint:disable=broad-except
logging.getLogger('ddb').exception("An error has occured while clearing caches",
exc_info=clear_cache_exception)
raise exception
finally:
os.chdir(initial_cwd)
if not reset_disabled:
Expand Down

0 comments on commit 8c0940a

Please sign in to comment.