]> git.ipfire.org Git - people/ms/bricklayer.git/commitdiff
Catch any exceptions and show an error message
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 5 May 2021 21:39:24 +0000 (21:39 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 5 May 2021 21:42:03 +0000 (21:42 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/__init__.py
src/python/step.py
src/python/tui/__init__.py

index ae90b5623cf22d4ea6d56ca37f97f5e1043248f8..2e1ed7b388589d5c7af26fd2edfc47999de970d0 100644 (file)
 ###############################################################################
 
 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):
                """
index e3a3a275573035050907e7a4f02da0bcb0bfe533..833fb98c4c65d56a7531a6d2cfde549097a56278 100644 (file)
@@ -74,7 +74,6 @@ class Welcome(Step):
                        buttons=(_("Start Installation"), _("Cancel"))
                )
 
-
 class UnattendedWarning(Step):
        @property
        def enabled(self):
index 3edc695fde4b6b3ed666d1548be0c2c48f52ed52..ce241f8c934ada182f7d65d584ad54f1e36ab617 100644 (file)
@@ -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)