From: Michael Tremer Date: Wed, 5 May 2021 21:39:24 +0000 (+0000) Subject: Catch any exceptions and show an error message X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=560b34d776c3c9231639c68de4f9391a45d200ba;p=people%2Fms%2Fbricklayer.git Catch any exceptions and show an error message Signed-off-by: Michael Tremer --- diff --git a/src/python/__init__.py b/src/python/__init__.py index ae90b56..2e1ed7b 100644 --- a/src/python/__init__.py +++ b/src/python/__init__.py @@ -19,12 +19,16 @@ ############################################################################### import logging +import sys +import traceback from . import disk from . import lang from . import logger from . import step from . import tui +from .i18n import _ +from .errors import * # Setup logging log = logging.getLogger("bricklayer") @@ -70,7 +74,30 @@ class Bricklayer(object): with self.tui: # Walk through all steps for step in self.steps: - self._run_step(step) + try: + self._run_step(step) + + # End installer if aborted + except InstallAbortedError: + return 1 + + # Catch all other exceptions and show an error + except: + type, value, tb = sys.exc_info() + + # Log the error + log.error("An unexpected error occured:", exc_info=True) + + # Format the exception + error = _("The installation cannot be continued due to an error:" + "\n\n%s") % "".join(traceback.format_exception(type, value, tb)) + + # Show an error message + self.tui.error(_("An Unexpected Error Occured"), + "".join(error), buttons=[_("Exit")], width=60) + + # Exit + return 1 def _run_step(self, stepcls): """ diff --git a/src/python/step.py b/src/python/step.py index e3a3a27..833fb98 100644 --- a/src/python/step.py +++ b/src/python/step.py @@ -74,7 +74,6 @@ class Welcome(Step): buttons=(_("Start Installation"), _("Cancel")) ) - class UnattendedWarning(Step): @property def enabled(self): diff --git a/src/python/tui/__init__.py b/src/python/tui/__init__.py index 3edc695..ce241f8 100644 --- a/src/python/tui/__init__.py +++ b/src/python/tui/__init__.py @@ -91,7 +91,7 @@ class Tui(object): self.screen.pushHelpLine(helpline) - def message(self, title, text, buttons=None, help=None): + def message(self, title, text, buttons=None, help=None, width=40): """ Shows a message to the user """ @@ -102,13 +102,13 @@ class Tui(object): buttons = (_("OK"), _("Cancel")) return snack.ButtonChoiceWindow(self.screen, title=title, text=text, - buttons=buttons, help=help) + buttons=buttons, width=width, help=help) - def error(self, title, text, buttons=None): + def error(self, title, text, buttons=None, width=40): if not buttons: buttons = [_("Abort Installation")] - return self.message(title, text, buttons=buttons) + return self.message(title, text, buttons=buttons, width=width) def progress(self, *args, **kwargs): return ProgressWindow(self, *args, **kwargs)