[master 25/30] Don't use exceptions' message attribute (#1014220)

M4rtinK installerbot-noreply at redhat.com
Mon Jun 1 14:04:42 UTC 2015


From: Vratislav Podzimek <vpodzime at redhat.com>

In Python 3 exceptions don't (necessarily) have the 'message' attribute. Just
use the str(e) call instead.
---
 pyanaconda/errors.py                 |  2 +-
 pyanaconda/kickstart.py              | 14 +++++++-------
 pyanaconda/packaging/dnfpayload.py   |  2 +-
 pyanaconda/ui/gui/spokes/custom.py   |  6 +++---
 pyanaconda/ui/gui/spokes/software.py |  2 +-
 pyanaconda/ui/helpers.py             |  4 ++--
 pyanaconda/ui/tui/spokes/software.py |  2 +-
 pyanaconda/ui/tui/spokes/storage.py  |  4 ++--
 8 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/pyanaconda/errors.py b/pyanaconda/errors.py
index 00f7523..b497553 100644
--- a/pyanaconda/errors.py
+++ b/pyanaconda/errors.py
@@ -268,7 +268,7 @@ def _payloadInstallHandler(self, exn):
     def _dependencyErrorHandler(self, exn):
         message = _("The following software marked for installation has errors.  "
                     "This is likely caused by an error with\nyour installation source.")
-        details = "\n".join(sorted(exn.message))
+        details = str(exn)
 
         self.ui.showDetailedError(message, details)
         return ERROR_RAISE
diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py
index 9be7e5b..c0ff012 100644
--- a/pyanaconda/kickstart.py
+++ b/pyanaconda/kickstart.py
@@ -343,7 +343,7 @@ def execute(self, storage, ksdata, instClass):
         doAutoPartition(storage, ksdata, min_luks_entropy=MIN_CREATE_ENTROPY)
         errors = sanity_check(storage)
         if errors:
-            raise PartitioningError("autopart failed:\n" + "\n".join(error.message for error in errors))
+            raise PartitioningError("autopart failed:\n" + "\n".join(str(error) for error in errors))
 
 class Bootloader(commands.bootloader.F21_Bootloader):
     def __init__(self, *args, **kwargs):
@@ -513,7 +513,7 @@ def execute(self, storage, ksdata, instClass):
                                        dataLevel=self.dataLevel,
                                        parents=members)
             except BTRFSValueError as e:
-                raise KickstartValueError(formatErrorMsg(self.lineno, msg=e.message))
+                raise KickstartValueError(formatErrorMsg(self.lineno, msg=str(e)))
 
             storage.createDevice(request)
 
@@ -1012,7 +1012,7 @@ def execute(self, storage, ksdata, instClass):
                                     percent=self.percent,
                                     **pool_args)
             except (StorageError, ValueError) as e:
-                raise KickstartValueError(formatErrorMsg(self.lineno, msg=e.message))
+                raise KickstartValueError(formatErrorMsg(self.lineno, msg=str(e)))
 
             storage.createDevice(request)
             if ty == "swap":
@@ -1318,7 +1318,7 @@ def execute(self, storage, ksdata, instClass):
             try:
                 request = storage.newTmpFS(**kwargs)
             except (StorageError, ValueError) as e:
-                raise KickstartValueError(formatErrorMsg(self.lineno, msg=e.message))
+                raise KickstartValueError(formatErrorMsg(self.lineno, msg=str(e)))
             storage.createDevice(request)
         else:
             # If a previous device has claimed this mount point, delete the
@@ -1333,7 +1333,7 @@ def execute(self, storage, ksdata, instClass):
             try:
                 request = storage.newPartition(**kwargs)
             except (StorageError, ValueError) as e:
-                raise KickstartValueError(formatErrorMsg(self.lineno, msg=e.message))
+                raise KickstartValueError(formatErrorMsg(self.lineno, msg=str(e)))
 
             storage.createDevice(request)
             if ty == "swap":
@@ -1525,7 +1525,7 @@ def execute(self, storage, ksdata, instClass):
             try:
                 request = storage.newMDArray(**kwargs)
             except (StorageError, ValueError) as e:
-                raise KickstartValueError(formatErrorMsg(self.lineno, msg=e.message))
+                raise KickstartValueError(formatErrorMsg(self.lineno, msg=str(e)))
 
             storage.createDevice(request)
 
@@ -1791,7 +1791,7 @@ def execute(self, storage, ksdata, instClass):
                                     name=self.vgname,
                                     peSize=pesize)
             except (StorageError, ValueError) as e:
-                raise KickstartValueError(formatErrorMsg(self.lineno, msg=e.message))
+                raise KickstartValueError(formatErrorMsg(self.lineno, msg=str(e)))
 
             storage.createDevice(request)
             if self.reserved_space:
diff --git a/pyanaconda/packaging/dnfpayload.py b/pyanaconda/packaging/dnfpayload.py
index 7212ea6..f19c1be 100644
--- a/pyanaconda/packaging/dnfpayload.py
+++ b/pyanaconda/packaging/dnfpayload.py
@@ -543,7 +543,7 @@ def checkSoftwareSelection(self):
         except dnf.exceptions.DepsolveError as e:
             msg = str(e)
             log.warning(msg)
-            raise packaging.DependencyError([msg])
+            raise packaging.DependencyError(msg)
 
         log.info("%d packages selected totalling %s",
                  len(self._base.transaction), self.spaceRequired)
diff --git a/pyanaconda/ui/gui/spokes/custom.py b/pyanaconda/ui/gui/spokes/custom.py
index e76bc7d..4b9d2ba 100644
--- a/pyanaconda/ui/gui/spokes/custom.py
+++ b/pyanaconda/ui/gui/spokes/custom.py
@@ -2343,12 +2343,12 @@ def _do_autopart(self):
         errors = [exn for exn in exns if isinstance(exn, SanityError) and not isinstance(exn, LUKSDeviceWithoutKeyError)]
         warnings = [exn for exn in exns if isinstance(exn, SanityWarning)]
         for error in errors:
-            log.error(error.message)
+            log.error("%s", error)
         for warning in warnings:
-            log.warning(warning.message)
+            log.warning("%s", warning)
 
         if errors:
-            messages = "\n".join(error.message for error in errors)
+            messages = "\n".join(str(error) for error in errors)
             log.error("doAutoPartition failed: %s", messages)
             self._reset_storage()
             self._error = messages
diff --git a/pyanaconda/ui/gui/spokes/software.py b/pyanaconda/ui/gui/spokes/software.py
index 834dddd..ca33a15 100644
--- a/pyanaconda/ui/gui/spokes/software.py
+++ b/pyanaconda/ui/gui/spokes/software.py
@@ -144,7 +144,7 @@ def checkSoftwareSelection(self):
         try:
             self.payload.checkSoftwareSelection()
         except DependencyError as e:
-            self._errorMsgs = "\n".join(sorted(e.message))
+            self._errorMsgs = str(e)
             hubQ.send_message(self.__class__.__name__, _("Error checking software dependencies"))
             self._tx_id = None
         else:
diff --git a/pyanaconda/ui/helpers.py b/pyanaconda/ui/helpers.py
index e6654b9..b7851a1 100644
--- a/pyanaconda/ui/helpers.py
+++ b/pyanaconda/ui/helpers.py
@@ -93,8 +93,8 @@ def checkStorage(self):
         hubQ.send_not_ready(self._mainSpokeClass)
         hubQ.send_message(self._mainSpokeClass, _("Checking storage configuration..."))
         exns = sanity_check(self.storage, min_ram=self._min_ram)
-        errors = [exn.message for exn in exns if isinstance(exn, SanityError)]
-        warnings = [exn.message for exn in exns if isinstance(exn, SanityWarning)]
+        errors = [str(exn) for exn in exns if isinstance(exn, SanityError)]
+        warnings = [str(exn) for exn in exns if isinstance(exn, SanityWarning)]
         (StorageChecker.errors, StorageChecker.warnings) = (errors, warnings)
         hubQ.send_ready(self._mainSpokeClass, True)
         for e in StorageChecker.errors:
diff --git a/pyanaconda/ui/tui/spokes/software.py b/pyanaconda/ui/tui/spokes/software.py
index 8117679..da9af12 100644
--- a/pyanaconda/ui/tui/spokes/software.py
+++ b/pyanaconda/ui/tui/spokes/software.py
@@ -249,7 +249,7 @@ def checkSoftwareSelection(self):
         try:
             self.payload.checkSoftwareSelection()
         except DependencyError as e:
-            self.errors = [e.message]
+            self.errors = [str(e)]
             self._tx_id = None
         else:
             self._tx_id = self.payload.txID
diff --git a/pyanaconda/ui/tui/spokes/storage.py b/pyanaconda/ui/tui/spokes/storage.py
index ee006bf..b28a231 100644
--- a/pyanaconda/ui/tui/spokes/storage.py
+++ b/pyanaconda/ui/tui/spokes/storage.py
@@ -399,8 +399,8 @@ def execute(self):
         else:
             print(_("Checking storage configuration..."))
             exns = sanity_check(self.storage)
-            errors = [exn.message for exn in exns if isinstance(exn, SanityError)]
-            warnings = [exn.message for exn in exns if isinstance(exn, SanityWarning)]
+            errors = [str(exn) for exn in exns if isinstance(exn, SanityError)]
+            warnings = [str(exn) for exn in exns if isinstance(exn, SanityWarning)]
             (self.errors, self.warnings) = (errors, warnings)
             for e in self.errors:
                 log.error(e)


-- 
To view this commit on github, visit https://github.com/rhinstaller/anaconda/commit/be5651ddae45be18c6f44bb1fe20ee86a586d3af


More information about the anaconda-patches mailing list