From 69f29969adcd97db8a1ab54ef2bbd5ec7f29a07e Mon Sep 17 00:00:00 2001 From: mathieui Date: Fri, 13 Oct 2017 00:47:21 +0200 Subject: Improve some bare or redundant excepts --- poezio/config.py | 2 +- poezio/daemon.py | 2 +- poezio/logger.py | 2 +- poezio/multiuserchat.py | 3 +-- poezio/plugin_manager.py | 18 +++++++----------- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/poezio/config.py b/poezio/config.py index 6fe4fa59..fdcc5cc5 100644 --- a/poezio/config.py +++ b/poezio/config.py @@ -360,7 +360,7 @@ class Config(RawConfigParser): try: with open(self.file_name, 'r', encoding='utf-8') as df: lines_before = [line.strip() for line in df] - except: + except OSError: log.error('Unable to read the config file %s', self.file_name, exc_info=True) diff --git a/poezio/daemon.py b/poezio/daemon.py index 20acfa8a..6de0ec3a 100755 --- a/poezio/daemon.py +++ b/poezio/daemon.py @@ -57,7 +57,7 @@ class Executor(threading.Thread): if self.filename: try: stdout = open(self.filename, self.redirection_mode) - except (OSError, IOError): + except OSError: log.error('Could not open redirection file: %s', self.filename, exc_info=True) return try: diff --git a/poezio/logger.py b/poezio/logger.py index 9a3c8a4e..e4ce4c5a 100644 --- a/poezio/logger.py +++ b/poezio/logger.py @@ -261,7 +261,7 @@ class Logger(object): else: try: fd.flush() # TODO do something better here? - except: + except OSError: log.error('Unable to flush the log file (%s)', os.path.join(log_dir, jid), exc_info=True) diff --git a/poezio/multiuserchat.py b/poezio/multiuserchat.py index 92101f23..23e0f7eb 100644 --- a/poezio/multiuserchat.py +++ b/poezio/multiuserchat.py @@ -172,8 +172,7 @@ def set_user_affiliation(xmpp, muc_jid, affiliation, nick=None, jid=None, reason try: return xmpp.plugin['xep_0045'].set_affiliation(str(muc_jid), str(jid) if jid else None, nick, affiliation) except: - import traceback - log.debug('Error setting the affiliation: %s', traceback.format_exc()) + log.debug('Error setting the affiliation: %s', exc_info=True) return False def cancel_config(xmpp, room): diff --git a/poezio/plugin_manager.py b/poezio/plugin_manager.py index 9e2a8084..8499cf51 100644 --- a/poezio/plugin_manager.py +++ b/poezio/plugin_manager.py @@ -266,17 +266,13 @@ class PluginManager(object): completion function that completes the name of the plugins, from all .py files in plugins_dir """ - try: - names = set() - for path_ in self.load_path: - try: - add = set(os.listdir(path_)) - names |= add - except: - pass - except OSError as e: - self.core.information('Completion failed: %s' % e, 'Error') - return False + names = set() + for path_ in self.load_path: + try: + add = set(os.listdir(path_)) + names |= add + except OSError: + pass plugins_files = [name[:-3] for name in names if name.endswith('.py') and name != '__init__.py' and not name.startswith('.')] plugins_files.sort() -- cgit v1.2.3