Improve some bare or redundant excepts

This commit is contained in:
mathieui 2017-10-13 00:47:21 +02:00
parent bbfb834827
commit 69f29969ad
5 changed files with 11 additions and 16 deletions

View file

@ -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)

View file

@ -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:

View file

@ -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)

View file

@ -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):

View file

@ -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()