[master 1/1] Remove uses of broad-except.

dashea installerbot-noreply at redhat.com
Mon Nov 9 15:34:09 UTC 2015


From: David Shea <dshea at redhat.com>

Catching Exception hides bugs and we should avoid it whenever possible.
Keep the broad excepts in TUI since it's using them to send the
exception elsewhere, and be more particular everywhere else.
---
 pyanaconda/anaconda_argparse.py | 30 ++++++++++++++++--------------
 pyanaconda/rescue.py            |  2 +-
 2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/pyanaconda/anaconda_argparse.py b/pyanaconda/anaconda_argparse.py
index 9096e08..3caf107 100644
--- a/pyanaconda/anaconda_argparse.py
+++ b/pyanaconda/anaconda_argparse.py
@@ -63,21 +63,23 @@ def get_help_width():
     if is_s390:
         return DEFAULT_HELP_WIDTH
 
-    help_width = DEFAULT_HELP_WIDTH
     try:
         data = fcntl.ioctl(sys.stdout, termios.TIOCGWINSZ, '1234')
         columns = int(struct.unpack('hh', data)[1])
-        # apply the right padding
-        columns = columns - RIGHT_PADDING
-        if columns > 0:
-            help_width = columns
-    # pylint: disable=broad-except
-    except Exception as e:
-        # detection failed, use the default
-        # NOTE: this could be caused by the COLUMNS string having a value
-        # that can't be converted to an integer
-        print("anaconda argparse: terminal size detection failed, using default width")
-        print(e)
+    except (IOError, ValueError) as e:
+        log.info("Unable to determine terminal width: %s", e)
+        print("terminal size detection failed, using default width")
+        return DEFAULT_HELP_WIDTH
+
+    log.debug("detected window size of %s", columns)
+
+    # apply the right padding
+    columns = columns - RIGHT_PADDING
+    if columns > 0:
+        help_width = columns
+    else:
+        help_width = DEFAULT_HELP_WIDTH
+
     return help_width
 
 class AnacondaArgumentParser(ArgumentParser):
@@ -350,8 +352,8 @@ def help_text(self, option):
                 with open(self._path) as lines:
                     for parsed_option, parsed_text in self.read(lines):
                         self._help_text[parsed_option] = parsed_text
-            except Exception:  # pylint: disable=broad-except
-                log.error("error reading help text file %s", self._path)
+            except IOError as e:
+                log.error("error reading help text file %s: %s", self._path, e)
 
         return self._help_text.get(option, "")
 
diff --git a/pyanaconda/rescue.py b/pyanaconda/rescue.py
index 722b1f6..b01eabe 100644
--- a/pyanaconda/rescue.py
+++ b/pyanaconda/rescue.py
@@ -382,7 +382,7 @@ def refresh(self, args=None):
                     pass
             except (ValueError, LookupError, SyntaxError, NameError):
                 pass
-            except Exception as e: # pylint: disable=broad-except
+            except (OSError, StorageError) as e:
                 if flags.automatedInstall:
                     msg = _("Run %s to unmount the system when you are finished.\n") % ANACONDA_CLEANUP
 


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


More information about the anaconda-patches mailing list