Skip to content

Commit

Permalink
Replace bare excepts with something more responsible
Browse files Browse the repository at this point in the history
In many cases, this is 'except Exception', but where a more specifc
exception was obvious, that is used instead.
  • Loading branch information
djmitche committed Sep 11, 2014
1 parent 915d683 commit a801d8e
Show file tree
Hide file tree
Showing 76 changed files with 137 additions and 165 deletions.
6 changes: 3 additions & 3 deletions apidocs/epyrun
Expand Up @@ -121,7 +121,7 @@ def main():
#get list of modules/pkgs on cmd-line
try:
i = sys.argv.index("--modules")
except:
except ValueError:
pass
else:
names = sys.argv[i+1:]
Expand All @@ -131,7 +131,7 @@ def main():
for i in range(len(names)):
try:
j = names[i].rindex('buildbot/')
except:
except ValueError:
raise SystemExit, 'You can only specify buildbot modules or packages'
else:
#strip off any leading directories before the 'twisted/'
Expand Down Expand Up @@ -164,7 +164,7 @@ def main():
reflect.namedModule(name)
except ImportError:
print 'import error:', name
except:
except Exception:
print 'other error:', name
else:
modnames.append(name)
Expand Down
2 changes: 1 addition & 1 deletion master/buildbot/buildslave/base.py
Expand Up @@ -443,7 +443,7 @@ def _disconnected(rref):
# handlers from being run. Bummer.
tport.offset = 0
tport.dataBuffer = ""
except:
except Exception:
# however, these hacks are pretty internal, so don't blow up if
# they fail or are unavailable
log.msg("failed to accelerate the shutdown process")
Expand Down
4 changes: 2 additions & 2 deletions master/buildbot/buildslave/libvirt.py
Expand Up @@ -63,7 +63,7 @@ def _process(self):
# Start doing some work - expects a deferred
try:
d2 = next_operation(*args, **kwargs)
except:
except Exception:
d2 = defer.fail()

# Whenever a piece of work is done, whether it worked or not
Expand Down Expand Up @@ -261,7 +261,7 @@ def start_instance(self, build):
else:
self.domain = yield self.connection.lookupByName(self.name)
yield self.domain.create()
except:
except Exception:
log.err(failure.Failure(),
"Cannot start a VM (%s), failing gracefully and triggering"
"a new build check" % self.name)
Expand Down
4 changes: 3 additions & 1 deletion master/buildbot/changes/bonsaipoller.py
Expand Up @@ -106,7 +106,9 @@ def __init__(self, data):
data = data.decode("latin1")
self.dom = minidom.parseString(data)
log.msg(data)
except:
# depending on the parser in use, this may raise errors from different
# hierarchies, so 'Exception' is the most specific we can be.
except Exception:
raise InvalidResultError("Malformed XML in result")

self.ciNodes = self.dom.getElementsByTagName("ci")
Expand Down
2 changes: 1 addition & 1 deletion master/buildbot/changes/gitpoller.py
Expand Up @@ -168,7 +168,7 @@ def poll(self):
revs[branch] = rev = yield self._dovccmd(
'rev-parse', [self._trackerBranch(branch)], path=self.workdir)
yield self._process_changes(rev, branch)
except:
except Exception:
log.err(_why="trying to poll branch %s of %s"
% (branch, self.repourl))

Expand Down
2 changes: 1 addition & 1 deletion master/buildbot/changes/hgpoller.py
Expand Up @@ -113,7 +113,7 @@ def process(output):
else:
try:
stamp = float(date.split()[0])
except:
except Exception:
log.msg('hgpoller: caught exception converting output %r '
'to timestamp' % date)
raise
Expand Down
6 changes: 3 additions & 3 deletions master/buildbot/changes/svnpoller.py
Expand Up @@ -133,7 +133,7 @@ def __init__(self, svnurl, split_file=None,
# try writing it, too
with open(self.cachepath, "w") as f:
f.write(str(self.last_change))
except:
except Exception:
self.cachepath = None
log.msg(("SVNPoller: SVNPoller(%s) cache file corrupt or unwriteable; " +
"skipping and not using") % self.svnurl)
Expand Down Expand Up @@ -302,8 +302,8 @@ def _get_text(self, element, tag_name):
try:
child_nodes = element.getElementsByTagName(tag_name)[0].childNodes
text = "".join([t.data for t in child_nodes])
except:
text = "<unknown>"
except IndexError:
text = "unknown"
return text

def _transform_path(self, path):
Expand Down
2 changes: 1 addition & 1 deletion master/buildbot/config.py
Expand Up @@ -177,7 +177,7 @@ def loadConfig(cls, basedir, filename):
for err in e.errors:
error(err)
raise errors
except:
except Exception:
log.err(failure.Failure(), 'error while parsing config file:')
error("error while parsing config file: %s (traceback in logfile)" %
(sys.exc_info()[1],),
Expand Down
2 changes: 1 addition & 1 deletion master/buildbot/data/types.py
Expand Up @@ -191,7 +191,7 @@ def validate(self, name, object):
yield "%s[%s] source %r is not unicode" % (name, k, propsrc)
try:
json.loads(propval)
except:
except ValueError:
yield "%s[%r] value is not JSON-able" % (name, k)


Expand Down
2 changes: 1 addition & 1 deletion master/buildbot/db/buildrequests.py
Expand Up @@ -183,7 +183,7 @@ def thd(conn):
(claims_tbl.c.brid.in_(batch))
& (claims_tbl.c.masterid == self.db.master.masterid))
conn.execute(q)
except:
except Exception:
transaction.rollback()
raise

Expand Down
2 changes: 1 addition & 1 deletion master/buildbot/db/changes.py
Expand Up @@ -285,7 +285,7 @@ def split_vs(vs):
v, s = vs
if s != "Change":
v, s = vs, "Change"
except:
except (ValueError, TypeError):
v, s = vs, "Change"
return v, s

Expand Down
4 changes: 2 additions & 2 deletions master/buildbot/db/enginestrategy.py
Expand Up @@ -54,7 +54,7 @@ def get_sqlalchemy_migrate_version():
version = "0.6.1"
else:
version = "0.6"
except:
except Exception:
version = "0.0"
return tuple(map(int, version.split('.')))

Expand Down Expand Up @@ -120,7 +120,7 @@ class CheckpointFullfsyncDisabler(object):
log.msg("setting database journal mode to 'wal'")
try:
engine.execute("pragma journal_mode = wal")
except:
except Exception:
log.msg("failed to set journal mode - database may fail")

def special_case_mysql(self, u, kwargs):
Expand Down
4 changes: 2 additions & 2 deletions master/buildbot/db/model.py
Expand Up @@ -690,7 +690,7 @@ def table_exists(engine, tbl):
r = engine.execute("select * from %s limit 1" % tbl)
r.close()
return True
except:
except Exception:
return False

# http://code.google.com/p/sqlalchemy-migrate/issues/detail?id=100
Expand All @@ -717,7 +717,7 @@ def check_sqlalchemy_migrate_version():
version = "0.6.1"
else:
version = "0.6"
except:
except Exception:
version = "0.0"
version_tup = tuple(map(int, version.split('.')))
log.msg("using SQLAlchemy-Migrate version %s" % (version,))
Expand Down
2 changes: 1 addition & 1 deletion master/buildbot/db/pool.py
Expand Up @@ -284,7 +284,7 @@ def get_sqlite_version(self):
r = conn.execute("SELECT sqlite_version()")
vers_row = r.fetchone()
r.close()
except:
except Exception:
return (0,)

if vers_row:
Expand Down
4 changes: 2 additions & 2 deletions master/buildbot/db/state.py
Expand Up @@ -104,7 +104,7 @@ def thd(conn):
return default
try:
return json.loads(row.value_json)
except:
except ValueError:
raise TypeError("JSON error loading state value '%s' for %d" %
(name, objectid))
return self.db.pool.do(thd)
Expand All @@ -115,7 +115,7 @@ def thd(conn):

try:
value_json = json.dumps(value)
except:
except (TypeError, ValueError):
raise TypeError("Error encoding JSON for %r" % (value,))

self.checkLength(object_state_tbl.c.name, name)
Expand Down
6 changes: 3 additions & 3 deletions master/buildbot/master.py
Expand Up @@ -217,7 +217,7 @@ def startService(self, _reactor=reactor):
log.msg("Halting master.")
_reactor.stop()
return
except:
except Exception:
log.err(failure.Failure(), 'while starting BuildMaster')
_reactor.stop()
return
Expand Down Expand Up @@ -263,7 +263,7 @@ def sigusr1(*args):
yield self.data.updates.masterActive(
name=self.name,
masterid=self.masterid)
except:
except Exception:
f = failure.Failure()
log.err(f, 'while starting BuildMaster')
_reactor.stop()
Expand Down Expand Up @@ -350,7 +350,7 @@ def doReconfig(self):
log.msg(msg)
failed = True

except:
except Exception:
log.err(failure.Failure(), 'during reconfig:')
failed = True

Expand Down
6 changes: 3 additions & 3 deletions master/buildbot/monkeypatches/bug4881.py
Expand Up @@ -138,15 +138,15 @@ def _getImplementation(self):
return self._devFDImplementation
else:
return self._fallbackFDImplementation
except:
except Exception: # chnanged in Bulidbot to avoid bare 'except'
try:
self.listdir("/proc/%d/fd" % (self.getpid(),))
return self._procFDImplementation
except:
except Exception: # chnanged in Bulidbot to avoid bare 'except'
try:
self._resourceFDImplementation() # Imports resource
return self._resourceFDImplementation
except:
except Exception: # chnanged in Bulidbot to avoid bare 'except'
return self._fallbackFDImplementation

def _checkDevFDSanity(self):
Expand Down
4 changes: 2 additions & 2 deletions master/buildbot/process/build.py
Expand Up @@ -264,7 +264,7 @@ def startBuild(self, build_status, expectations, slavebuilder):

try:
self.setupBuild(expectations) # create .steps
except:
except Exception:
# the build hasn't started yet, so log the exception as a point
# event instead of flunking the build.
# TODO: associate this failure with the build instead.
Expand Down Expand Up @@ -523,7 +523,7 @@ def buildException(self, why):
# this may not work well.
try:
self.buildFinished(["build", "exception"], EXCEPTION)
except:
except Exception:
log.err(Failure(), 'while finishing a build with an exception')

def buildFinished(self, text, results):
Expand Down
8 changes: 4 additions & 4 deletions master/buildbot/process/builder.py
Expand Up @@ -315,7 +315,7 @@ def run_cleanups():
while cleanups:
fn = cleanups.pop()
fn()
except:
except Exception:
log.err(failure.Failure(), "while running %r" % (run_cleanups,))

# the last cleanup we want to perform is to update the big
Expand All @@ -342,7 +342,7 @@ def run_cleanups():

try:
ready = yield slavebuilder.prepare(self.builder_status, build)
except:
except Exception:
log.err(failure.Failure(), 'while preparing slavebuilder:')
ready = False

Expand All @@ -367,7 +367,7 @@ def run_cleanups():
% (build, slavebuilder))
try:
ping_success = yield slavebuilder.ping()
except:
except Exception:
log.err(failure.Failure(), 'while pinging slave before build:')
ping_success = False

Expand All @@ -386,7 +386,7 @@ def run_cleanups():
# tell the remote that it's starting a build, too
try:
yield slavebuilder.slave.conn.remoteStartBuild(build.builder.name)
except:
except Exception:
log.err(failure.Failure(), 'while calling remote startBuild:')
run_cleanups()
defer.returnValue(False)
Expand Down
4 changes: 2 additions & 2 deletions master/buildbot/process/metrics.py
Expand Up @@ -327,7 +327,7 @@ def _get_rss():
try:
with open("/proc/%i/statm" % os.getpid()) as f:
return int(f.read().split()[1])
except:
except Exception:
return 0
return 0

Expand Down Expand Up @@ -492,5 +492,5 @@ def report(self):
continue
for line in report.split("\n"):
log.msg(line)
except:
except Exception:
log.err(None, "generating metric report")
2 changes: 1 addition & 1 deletion master/buildbot/process/remotecommand.py
Expand Up @@ -168,7 +168,7 @@ def remote_update(self, updates):
try:
if self.active and not self.ignore_updates:
self.remoteUpdate(update)
except:
except Exception:
# log failure, terminate build, let slave retire the update
self._finished(Failure())
# TODO: what if multiple updates arrive? should
Expand Down
2 changes: 1 addition & 1 deletion master/buildbot/schedulers/base.py
Expand Up @@ -151,7 +151,7 @@ def _changeCallback(self, key, msg, fileIsImportant, change_filter,
important = fileIsImportant(change)
if not important and onlyImportant:
return
except:
except Exception:
log.err(failure.Failure(),
'in fileIsImportant check for %s' % change)
return
Expand Down
2 changes: 1 addition & 1 deletion master/buildbot/scripts/base.py
Expand Up @@ -145,7 +145,7 @@ def loadOptionsFile(self, _here=None):
with open(optfile, "r") as f:
options = f.read()
exec options in localDict
except:
except Exception:
print "error while reading %s" % optfile
raise
break
Expand Down
4 changes: 2 additions & 2 deletions master/buildbot/scripts/runner.py
Expand Up @@ -47,7 +47,7 @@ def validateMasterOption(master):
try:
hostname, port = master.split(":")
port = int(port)
except:
except (TypeError, ValueError):
raise usage.UsageError("master must have the form 'hostname:port'")


Expand Down Expand Up @@ -277,7 +277,7 @@ def postOptions(self):
if self.get('when'):
try:
self['when'] = float(self['when'])
except:
except (TypeError, ValueError):
raise usage.UsageError('invalid "when" value %s'
% (self['when'],))
else:
Expand Down
2 changes: 1 addition & 1 deletion master/buildbot/scripts/sendchange.py
Expand Up @@ -47,7 +47,7 @@ def sendchange(config):
category=category, when=when, properties=properties,
repository=repository, vc=vc, project=project, revlink=revlink,
codebase=codebase)
except:
except Exception:
print "change not sent:"
traceback.print_exc(file=sys.stdout)
defer.returnValue(1)
Expand Down
4 changes: 2 additions & 2 deletions master/buildbot/scripts/stop.py
Expand Up @@ -37,7 +37,7 @@ def stop(config, signame="TERM", wait=False):
try:
with open(pidfile, "rt") as f:
pid = int(f.read().strip())
except:
except Exception:
if not config['quiet']:
print "buildmaster not running"
return 0
Expand All @@ -53,7 +53,7 @@ def stop(config, signame="TERM", wait=False):
print "buildmaster not running"
try:
os.unlink(pidfile)
except:
except OSError:
pass
return 0

Expand Down
2 changes: 1 addition & 1 deletion master/buildbot/scripts/upgrade_master.py
Expand Up @@ -69,7 +69,7 @@ def loadConfig(config, configFileName='master.cfg'):
for msg in e.errors:
print " " + msg
return
except:
except Exception:
print "Errors loading configuration:"
traceback.print_exc(file=sys.stdout)
return
Expand Down

0 comments on commit a801d8e

Please sign in to comment.