[master 1/2] Beware of the 'except Exception as e' hiding our local variable

vpodzime installerbot-noreply at redhat.com
Fri Oct 23 11:49:47 UTC 2015


From: Vratislav Podzimek <vpodzime at redhat.com>

If there's a variable 'e' and then 'except Exception as e' appears and really
catches an exception, the variable 'e' no longer exists after the 'except' block
is left. Let's just use a better name for the variable.

Also 'raise' is a statement not a function.
---
 blivet/devicefactory.py | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/blivet/devicefactory.py b/blivet/devicefactory.py
index 0c795be..6689380 100644
--- a/blivet/devicefactory.py
+++ b/blivet/devicefactory.py
@@ -639,18 +639,19 @@ def _create_device(self):
             raise
 
         self.storage.createDevice(device)
-        e = None
+        error = None
         try:
             self._post_create()
         except (StorageError, blockdev.BlockDevError) as e:
             log.error("device post-create method failed: %s", e)
+            error = e
         else:
             if not device.size:
-                e = StorageError("failed to create device")
+                error = StorageError("failed to create device")
 
-        if e:
+        if error:
             self.storage.destroyDevice(device)
-            raise StorageError(e)
+            raise StorageError(error)
 
         ret = device
         if self.encrypted:
@@ -825,7 +826,7 @@ def configure(self):
             if not isinstance(e, (StorageError, OverflowError)):
                 e = DeviceFactoryError(str(e))
 
-            raise(e)
+            raise e
 
     def _configure(self):
         self._set_container()


-- 
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/ee106127b2c71a3e988e7b2c47b6357321050840


More information about the anaconda-patches mailing list