[master/rhel7-branch] Error gracefully if we have a question in cmdline mode. (#869731), v02

Samantha N. Bueno sbueno+anaconda at redhat.com
Thu Jan 9 17:00:37 UTC 2014


(Take two, with mulhern's and vpodzime's suggestions.)

Show a nice error message before bailing instead of just crashing.

Resolves: rhbz#869731
---
 pyanaconda/errors.py              |  6 ++++--
 pyanaconda/exception.py           | 14 ++++++++++++++
 pyanaconda/ui/tui/hubs/summary.py |  3 ++-
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/pyanaconda/errors.py b/pyanaconda/errors.py
index 6fe7bba..744f0f5 100644
--- a/pyanaconda/errors.py
+++ b/pyanaconda/errors.py
@@ -19,12 +19,11 @@
 # Author(s): Chris Lumens <clumens at redhat.com>
 
 from pyanaconda.i18n import _
-from pyanaconda.ui.tui import TextUserInterface
 
 __all__ = ["ERROR_RAISE", "ERROR_CONTINUE", "ERROR_RETRY",
            "ErrorHandler",
            "InvalidImageSizeError", "MissingImageError", "MediaUnmountError",
-           "MediaMountError", "ScriptError",
+           "MediaMountError", "ScriptError", "CmdlineError",
            "errorHandler"]
 
 class InvalidImageSizeError(Exception):
@@ -42,6 +41,9 @@ class MediaUnmountError(Exception):
 class ScriptError(Exception):
     pass
 
+class CmdlineError(Exception):
+    pass
+
 # These constants are returned by the callback in the ErrorHandler class.
 # Each represents a different kind of action the caller can take:
 #
diff --git a/pyanaconda/exception.py b/pyanaconda/exception.py
index a32f318..ca3471e 100644
--- a/pyanaconda/exception.py
+++ b/pyanaconda/exception.py
@@ -32,6 +32,7 @@ import signal
 import time
 import kickstart
 import blivet.errors
+from pyanaconda.errors import CmdlineError
 from pyanaconda.ui.communication import hubQ
 from pyanaconda.constants import ROOT_PATH, THREAD_EXCEPTION_HANDLING_TEST
 from pyanaconda.threads import threadMgr
@@ -90,6 +91,19 @@ class AnacondaExceptionHandler(ExceptionHandler):
                              "The installer will now terminate.") % str(value)
             self.intf.messageWindow(_("Hardware error occured"), hw_error_msg)
             sys.exit(0)
+        elif (issubclass (ty, CmdlineError)):
+
+            cmdline_error_msg = _("\nThe installation was stopped due to "
+                                  "incomplete spokes detected while running "
+                                  "in non-interactive cmdline mode. Since there "
+                                  "can not be any questions in cmdline mode, "
+                                  "edit your kickstart file and retry "
+                                  "installation.\nThe exact error message is: "
+                                  "\n\n%s.\n\nThe installer will now terminate.") % str(value)
+            print(cmdline_error_msg)
+            # sleep for a bit so the error message has a chance of being seen
+            time.sleep(10)
+            sys.exit(0)
         else:
             try:
                 # pylint: disable-msg=E0611
diff --git a/pyanaconda/ui/tui/hubs/summary.py b/pyanaconda/ui/tui/hubs/summary.py
index 78bd5fc..5865033 100644
--- a/pyanaconda/ui/tui/hubs/summary.py
+++ b/pyanaconda/ui/tui/hubs/summary.py
@@ -22,6 +22,7 @@
 
 from pyanaconda.ui.tui.hubs import TUIHub
 from pyanaconda.flags import flags
+from pyanaconda.errors import CmdlineError
 from pyanaconda.i18n import _
 import sys
 import time
@@ -61,6 +62,6 @@ class SummaryHub(TUIHub):
         if not flags.ksprompt:
             errtxt = _("The following mandatory spokes are not completed:") + \
                      "\n" + "\n".join(spoke.title for spoke in incompleteSpokes)
-            raise RuntimeError(errtxt)
+            raise CmdlineError(errtxt)
 
         return TUIHub.prompt(self, args)
-- 
1.8.3.1



More information about the anaconda-patches mailing list