From a801d8e9b55bcd5876de18aea4f2993349375cd2 Mon Sep 17 00:00:00 2001 From: "Dustin J. Mitchell" Date: Thu, 11 Sep 2014 18:36:04 -0400 Subject: [PATCH] Replace bare excepts with something more responsible In many cases, this is 'except Exception', but where a more specifc exception was obvious, that is used instead. --- apidocs/epyrun | 6 +-- master/buildbot/buildslave/base.py | 2 +- master/buildbot/buildslave/libvirt.py | 4 +- master/buildbot/changes/bonsaipoller.py | 4 +- master/buildbot/changes/gitpoller.py | 2 +- master/buildbot/changes/hgpoller.py | 2 +- master/buildbot/changes/svnpoller.py | 6 +-- master/buildbot/config.py | 2 +- master/buildbot/data/types.py | 2 +- master/buildbot/db/buildrequests.py | 2 +- master/buildbot/db/changes.py | 2 +- master/buildbot/db/enginestrategy.py | 4 +- master/buildbot/db/model.py | 4 +- master/buildbot/db/pool.py | 2 +- master/buildbot/db/state.py | 4 +- master/buildbot/master.py | 6 +-- master/buildbot/monkeypatches/bug4881.py | 6 +-- master/buildbot/process/build.py | 4 +- master/buildbot/process/builder.py | 8 ++-- master/buildbot/process/metrics.py | 4 +- master/buildbot/process/remotecommand.py | 2 +- master/buildbot/schedulers/base.py | 2 +- master/buildbot/scripts/base.py | 2 +- master/buildbot/scripts/runner.py | 4 +- master/buildbot/scripts/sendchange.py | 2 +- master/buildbot/scripts/stop.py | 4 +- master/buildbot/scripts/upgrade_master.py | 2 +- master/buildbot/status/build.py | 2 +- master/buildbot/status/builder.py | 8 ++-- master/buildbot/status/buildrequest.py | 3 +- master/buildbot/status/master.py | 6 +-- master/buildbot/status/progress.py | 4 +- master/buildbot/steps/package/rpm/rpmbuild.py | 2 +- master/buildbot/steps/shell.py | 2 +- master/buildbot/steps/source/gerrit.py | 2 +- master/buildbot/steps/source/git.py | 2 +- master/buildbot/steps/source/svn.py | 3 +- master/buildbot/test/fake/fakedata.py | 2 +- master/buildbot/test/fake/fakedb.py | 2 +- .../test/integration/test_slave_comm.py | 2 +- .../test_changes_mail_CVSMaildirSource.py | 45 ++++--------------- .../test/unit/test_changes_svnpoller.py | 14 ++++++ .../unit/test_contrib_buildbot_cvs_mail.py | 2 +- ...ersions_019_merge_schedulers_to_objects.py | 2 +- ...igrate_versions_020_remove_change_links.py | 2 +- .../test/unit/test_schedulers_manager.py | 2 +- .../buildbot/test/unit/test_status_logfile.py | 6 +-- master/buildbot/test/util/db.py | 2 +- master/buildbot/test/util/validation.py | 4 +- master/buildbot/util/croniter.py | 2 +- master/buildbot/util/eventual.py | 2 +- master/buildbot/util/maildir.py | 4 +- master/buildbot/util/sautils.py | 2 +- master/buildbot/util/subscription.py | 2 +- master/buildbot/www/resource.py | 2 +- master/contrib/SimpleConfig.py | 4 +- master/contrib/buildbot_cvs_mail.py | 2 +- master/contrib/bzr_buildbot.py | 4 +- master/contrib/check_buildbot.py | 6 +-- master/contrib/coverage2text.py | 4 +- master/contrib/git_buildbot.py | 4 +- master/contrib/googlecode_atom.py | 2 +- master/contrib/run_maxq.py | 2 +- master/contrib/svnpoller.py | 4 +- master/docs/manual/optimization.rst | 2 +- slave/buildslave/bot.py | 4 +- slave/buildslave/commands/base.py | 2 +- slave/buildslave/commands/bk.py | 10 +---- slave/buildslave/commands/transfer.py | 2 +- slave/buildslave/commands/utils.py | 2 +- slave/buildslave/monkeypatches/bug4881.py | 6 +-- slave/buildslave/runprocess.py | 5 +-- slave/buildslave/scripts/stop.py | 2 +- .../test/unit/test_commands_utils.py | 4 +- slave/buildslave/test/unit/test_runprocess.py | 2 +- slave/buildslave/test/util/command.py | 2 +- 76 files changed, 137 insertions(+), 165 deletions(-) diff --git a/apidocs/epyrun b/apidocs/epyrun index a1ce067e41a..7358e370d70 100644 --- a/apidocs/epyrun +++ b/apidocs/epyrun @@ -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:] @@ -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/' @@ -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) diff --git a/master/buildbot/buildslave/base.py b/master/buildbot/buildslave/base.py index c1a4c231645..0a959950ba3 100644 --- a/master/buildbot/buildslave/base.py +++ b/master/buildbot/buildslave/base.py @@ -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") diff --git a/master/buildbot/buildslave/libvirt.py b/master/buildbot/buildslave/libvirt.py index 2266f027b39..c36e459a642 100644 --- a/master/buildbot/buildslave/libvirt.py +++ b/master/buildbot/buildslave/libvirt.py @@ -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 @@ -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) diff --git a/master/buildbot/changes/bonsaipoller.py b/master/buildbot/changes/bonsaipoller.py index bc88b1a2af8..2a7795dfea5 100644 --- a/master/buildbot/changes/bonsaipoller.py +++ b/master/buildbot/changes/bonsaipoller.py @@ -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") diff --git a/master/buildbot/changes/gitpoller.py b/master/buildbot/changes/gitpoller.py index 994dc4bbe9e..dfeae22e43b 100644 --- a/master/buildbot/changes/gitpoller.py +++ b/master/buildbot/changes/gitpoller.py @@ -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)) diff --git a/master/buildbot/changes/hgpoller.py b/master/buildbot/changes/hgpoller.py index 081d84dfaf0..dc49950f6cb 100644 --- a/master/buildbot/changes/hgpoller.py +++ b/master/buildbot/changes/hgpoller.py @@ -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 diff --git a/master/buildbot/changes/svnpoller.py b/master/buildbot/changes/svnpoller.py index 236e112c04c..1b64af436a4 100644 --- a/master/buildbot/changes/svnpoller.py +++ b/master/buildbot/changes/svnpoller.py @@ -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) @@ -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 = "" + except IndexError: + text = "unknown" return text def _transform_path(self, path): diff --git a/master/buildbot/config.py b/master/buildbot/config.py index dc35c520f39..45f17cfed83 100644 --- a/master/buildbot/config.py +++ b/master/buildbot/config.py @@ -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],), diff --git a/master/buildbot/data/types.py b/master/buildbot/data/types.py index 62925e9a933..a3a8d772949 100644 --- a/master/buildbot/data/types.py +++ b/master/buildbot/data/types.py @@ -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) diff --git a/master/buildbot/db/buildrequests.py b/master/buildbot/db/buildrequests.py index 654cd39d267..de4ad2acea4 100644 --- a/master/buildbot/db/buildrequests.py +++ b/master/buildbot/db/buildrequests.py @@ -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 diff --git a/master/buildbot/db/changes.py b/master/buildbot/db/changes.py index e6c9b3245f3..89e9b9d3055 100644 --- a/master/buildbot/db/changes.py +++ b/master/buildbot/db/changes.py @@ -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 diff --git a/master/buildbot/db/enginestrategy.py b/master/buildbot/db/enginestrategy.py index 88790f6f559..cfb53d4c53b 100644 --- a/master/buildbot/db/enginestrategy.py +++ b/master/buildbot/db/enginestrategy.py @@ -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('.'))) @@ -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): diff --git a/master/buildbot/db/model.py b/master/buildbot/db/model.py index 205048f6307..48ad3ea495d 100644 --- a/master/buildbot/db/model.py +++ b/master/buildbot/db/model.py @@ -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 @@ -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,)) diff --git a/master/buildbot/db/pool.py b/master/buildbot/db/pool.py index 50ffe60ff00..cd4ea2d3854 100644 --- a/master/buildbot/db/pool.py +++ b/master/buildbot/db/pool.py @@ -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: diff --git a/master/buildbot/db/state.py b/master/buildbot/db/state.py index 29d157629b5..398bedf43b5 100644 --- a/master/buildbot/db/state.py +++ b/master/buildbot/db/state.py @@ -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) @@ -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) diff --git a/master/buildbot/master.py b/master/buildbot/master.py index 551b2f0bbbf..71019c13156 100644 --- a/master/buildbot/master.py +++ b/master/buildbot/master.py @@ -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 @@ -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() @@ -350,7 +350,7 @@ def doReconfig(self): log.msg(msg) failed = True - except: + except Exception: log.err(failure.Failure(), 'during reconfig:') failed = True diff --git a/master/buildbot/monkeypatches/bug4881.py b/master/buildbot/monkeypatches/bug4881.py index 56acce98096..d86a97f8a8f 100644 --- a/master/buildbot/monkeypatches/bug4881.py +++ b/master/buildbot/monkeypatches/bug4881.py @@ -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): diff --git a/master/buildbot/process/build.py b/master/buildbot/process/build.py index a7cf8218a0d..99748f5f7d2 100644 --- a/master/buildbot/process/build.py +++ b/master/buildbot/process/build.py @@ -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. @@ -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): diff --git a/master/buildbot/process/builder.py b/master/buildbot/process/builder.py index 360fa730cfb..f0f4f3cb469 100644 --- a/master/buildbot/process/builder.py +++ b/master/buildbot/process/builder.py @@ -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 @@ -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 @@ -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 @@ -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) diff --git a/master/buildbot/process/metrics.py b/master/buildbot/process/metrics.py index f71584da58d..4af4e79d339 100644 --- a/master/buildbot/process/metrics.py +++ b/master/buildbot/process/metrics.py @@ -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 @@ -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") diff --git a/master/buildbot/process/remotecommand.py b/master/buildbot/process/remotecommand.py index b25d3458046..b7b188ee435 100644 --- a/master/buildbot/process/remotecommand.py +++ b/master/buildbot/process/remotecommand.py @@ -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 diff --git a/master/buildbot/schedulers/base.py b/master/buildbot/schedulers/base.py index 50fddafbd8f..7236904e727 100644 --- a/master/buildbot/schedulers/base.py +++ b/master/buildbot/schedulers/base.py @@ -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 diff --git a/master/buildbot/scripts/base.py b/master/buildbot/scripts/base.py index b2c4874d4fa..5a2bcc4f5aa 100644 --- a/master/buildbot/scripts/base.py +++ b/master/buildbot/scripts/base.py @@ -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 diff --git a/master/buildbot/scripts/runner.py b/master/buildbot/scripts/runner.py index eb971a66b13..ee687b14753 100644 --- a/master/buildbot/scripts/runner.py +++ b/master/buildbot/scripts/runner.py @@ -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'") @@ -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: diff --git a/master/buildbot/scripts/sendchange.py b/master/buildbot/scripts/sendchange.py index 2e8fe4f33ed..7963e647708 100644 --- a/master/buildbot/scripts/sendchange.py +++ b/master/buildbot/scripts/sendchange.py @@ -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) diff --git a/master/buildbot/scripts/stop.py b/master/buildbot/scripts/stop.py index 928d8ab717b..c9b73150f99 100644 --- a/master/buildbot/scripts/stop.py +++ b/master/buildbot/scripts/stop.py @@ -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 @@ -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 diff --git a/master/buildbot/scripts/upgrade_master.py b/master/buildbot/scripts/upgrade_master.py index b0490d70ac1..5f9ca70f8a1 100644 --- a/master/buildbot/scripts/upgrade_master.py +++ b/master/buildbot/scripts/upgrade_master.py @@ -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 diff --git a/master/buildbot/status/build.py b/master/buildbot/status/build.py index 2c937d4ee28..372cc67b128 100644 --- a/master/buildbot/status/build.py +++ b/master/buildbot/status/build.py @@ -429,7 +429,7 @@ def saveYourself(self): if os.path.exists(filename): os.unlink(filename) os.rename(tmpfilename, filename) - except: + except Exception: log.msg("unable to save build %s-#%d" % (self.builder.name, self.number)) log.err() diff --git a/master/buildbot/status/builder.py b/master/buildbot/status/builder.py index 3cb3a88efd7..2b11dd6aae6 100644 --- a/master/buildbot/status/builder.py +++ b/master/buildbot/status/builder.py @@ -169,7 +169,7 @@ def saveYourself(self): if os.path.exists(filename): os.unlink(filename) os.rename(tmpfilename, filename) - except: + except Exception: log.msg("unable to save builder %s" % self.name) log.err() @@ -523,7 +523,7 @@ def publishState(self, target=None): for w in self.watchers: try: w.builderChangedState(self.name, state) - except: + except Exception: log.msg("Exception caught publishing state to %r" % w) log.err() @@ -564,7 +564,7 @@ def buildStarted(self, s): s.subscribe(receiver) d = s.waitUntilFinished() d.addCallback(lambda s: s.unsubscribe(receiver)) - except: + except Exception: log.msg("Exception caught notifying %r of buildStarted event" % w) log.err() @@ -578,7 +578,7 @@ def _buildFinished(self, s): for w in self.watchers: try: w.buildFinished(name, s, results) - except: + except Exception: log.msg("Exception caught notifying %r of buildFinished event" % w) log.err() diff --git a/master/buildbot/status/buildrequest.py b/master/buildbot/status/buildrequest.py index 6bfd3953eb1..3cc75f5bc1b 100644 --- a/master/buildbot/status/buildrequest.py +++ b/master/buildbot/status/buildrequest.py @@ -61,9 +61,8 @@ def _getBuildRequest(self): br = yield buildrequest.BuildRequest.fromBrdict(self.master, self._brdict) self._buildrequest = br - except: # try/finally isn't allowed in generators in older Pythons + finally: self._buildrequest_lock.release() - raise self._buildrequest_lock.release() diff --git a/master/buildbot/status/master.py b/master/buildbot/status/master.py index 64956840ef6..a6b32414e9b 100644 --- a/master/buildbot/status/master.py +++ b/master/buildbot/status/master.py @@ -358,10 +358,8 @@ def builderAdded(self, name, basedir, tags=None, description=None): except IOError: log.msg("no saved status pickle, creating a new one") - except: - log.msg("error while loading status pickle, creating a new one") - log.msg("error follows:") - log.err() + except Exception: + log.err("error while loading status pickle, creating a new one") if not builder_status: builder_status = builder.BuilderStatus(name, tags, self.master, description) diff --git a/master/buildbot/status/progress.py b/master/buildbot/status/progress.py index 6e1f1f65fd6..a5e434139ed 100644 --- a/master/buildbot/status/progress.py +++ b/master/buildbot/status/progress.py @@ -253,8 +253,8 @@ def sendUpdate(self, remote, last=0): remote.callRemote("progress", self.remaining()) if last: remote.callRemote("finished", self) - except: - log.deferr() + except Exception: + log.err('while updating remote progress') self.removeWatcher(remote) def watcherTimeout(self, remote): diff --git a/master/buildbot/steps/package/rpm/rpmbuild.py b/master/buildbot/steps/package/rpm/rpmbuild.py index 56c2e2b5b8b..73bfabbf2bf 100644 --- a/master/buildbot/steps/package/rpm/rpmbuild.py +++ b/master/buildbot/steps/package/rpm/rpmbuild.py @@ -97,7 +97,7 @@ def start(self): try: with open(relfile, 'r') as rfile: rel = int(rfile.readline().strip()) - except: + except (IOError, TypeError, ValueError): rel = 0 self.rpmbuild = self.rpmbuild + ' --define "_release %s"' % rel with open(relfile, 'w') as rfile: diff --git a/master/buildbot/steps/shell.py b/master/buildbot/steps/shell.py index 37495111f6d..0f57185fc65 100644 --- a/master/buildbot/steps/shell.py +++ b/master/buildbot/steps/shell.py @@ -219,7 +219,7 @@ def _describe(self, done=False): return ["'%s" % words[0], "%s'" % words[1]] return ["'%s" % words[0], "%s" % words[1], "...'"] - except: + except Exception: log.err(failure.Failure(), "Error describing step") return ["???"] diff --git a/master/buildbot/steps/source/gerrit.py b/master/buildbot/steps/source/gerrit.py index 07c896d6b8d..5ad23f4eed8 100644 --- a/master/buildbot/steps/source/gerrit.py +++ b/master/buildbot/steps/source/gerrit.py @@ -33,7 +33,7 @@ def startVC(self, branch, revision, patch): gerrit_branch = "refs/changes/%2.2d/%d/%d" \ % (int(change[0]) % 100, int(change[0]), int(change[1])) self.updateSourceProperty("gerrit_branch", gerrit_branch) - except: + except Exception: pass branch = gerrit_branch or branch diff --git a/master/buildbot/steps/source/git.py b/master/buildbot/steps/source/git.py index f0ae82d7aa8..195629bf8d6 100644 --- a/master/buildbot/steps/source/git.py +++ b/master/buildbot/steps/source/git.py @@ -332,7 +332,7 @@ def parseCommitDescription(self, _=None): stdout = yield self._dovccmd(cmd, collectStdout=True) desc = stdout.strip() self.updateSourceProperty('commit-description', desc) - except: + except Exception: pass defer.returnValue(0) diff --git a/master/buildbot/steps/source/svn.py b/master/buildbot/steps/source/svn.py index 700fb98fcff..a73905abfe2 100644 --- a/master/buildbot/steps/source/svn.py +++ b/master/buildbot/steps/source/svn.py @@ -166,9 +166,8 @@ def copy(self): old_workdir = self.workdir self.workdir = 'source' yield self.incremental(None) - except: # finally doesn't work in python-2.4 + finally: self.workdir = old_workdir - raise self.workdir = old_workdir # if we're copying, copy; otherwise, export from source to build diff --git a/master/buildbot/test/fake/fakedata.py b/master/buildbot/test/fake/fakedata.py index aa5c191064b..779c081479c 100644 --- a/master/buildbot/test/fake/fakedata.py +++ b/master/buildbot/test/fake/fakedata.py @@ -65,7 +65,7 @@ def assertProperties(self, sourced, properties): propval = v try: json.dumps(propval) - except: + except (TypeError, ValueError): self.testcase.fail("value for %s is not JSON-able" % (k,)) # update methods diff --git a/master/buildbot/test/fake/fakedb.py b/master/buildbot/test/fake/fakedb.py index cecdaf7676c..0f4a80077f0 100644 --- a/master/buildbot/test/fake/fakedb.py +++ b/master/buildbot/test/fake/fakedb.py @@ -1413,7 +1413,7 @@ def _newId(self): def getObjectId(self, name, class_name): try: id = self.objects[(name, class_name)] - except: + except KeyError: # invent a new id and add it id = self.objects[(name, class_name)] = self._newId() self.states[id] = {} diff --git a/master/buildbot/test/integration/test_slave_comm.py b/master/buildbot/test/integration/test_slave_comm.py index 6142dc20fb5..f074092b5ae 100644 --- a/master/buildbot/test/integration/test_slave_comm.py +++ b/master/buildbot/test/integration/test_slave_comm.py @@ -282,7 +282,7 @@ def test_duplicate_slave(self): try: yield self.connectSlave(waitForBuilderList=False) connect_failed = False - except: + except Exception: connect_failed = True self.assertTrue(connect_failed) diff --git a/master/buildbot/test/unit/test_changes_mail_CVSMaildirSource.py b/master/buildbot/test/unit/test_changes_mail_CVSMaildirSource.py index 13486776c59..b0588673f11 100644 --- a/master/buildbot/test/unit/test_changes_mail_CVSMaildirSource.py +++ b/master/buildbot/test/unit/test_changes_mail_CVSMaildirSource.py @@ -77,10 +77,7 @@ class TestCVSMaildirSource(unittest.TestCase): def test_CVSMaildirSource_create_change_from_cvs1_11msg(self): m = message_from_string(cvs1_11_msg) src = CVSMaildirSource('/dev/null') - try: - src, chdict = src.parse(m) - except: - self.fail('Failed to get change from email message.') + src, chdict = src.parse(m) self.assertNotEqual(chdict, None) self.assertEqual(chdict['author'], 'andy') self.assertEqual(len(chdict['files']), 1) @@ -99,10 +96,7 @@ def test_CVSMaildirSource_create_change_from_cvs1_11msg(self): def test_CVSMaildirSource_create_change_from_cvs1_12msg(self): m = message_from_string(cvs1_12_msg) src = CVSMaildirSource('/dev/null') - try: - src, chdict = src.parse(m) - except: - self.fail('Failed to get change from email message.') + src, chdict = src.parse(m) self.assertNotEqual(chdict, None) self.assertEqual(chdict['author'], 'andy') self.assertEqual(len(chdict['files']), 2) @@ -148,20 +142,14 @@ def test_CVSMaildirSource_create_change_with_branch(self): ' Tag: Test_Branch\n GNUmakefile') m = message_from_string(msg) src = CVSMaildirSource('/dev/null') - try: - chdict = src.parse(m)[1] - except: - self.fail('Failed to get change from email message.') + chdict = src.parse(m)[1] self.assertEqual(chdict['branch'], 'Test_Branch') def test_CVSMaildirSource_create_change_with_category(self): msg = cvs1_11_msg.replace('Category: None', 'Category: Test category') m = message_from_string(msg) src = CVSMaildirSource('/dev/null') - try: - chdict = src.parse(m)[1] - except: - self.fail('Failed to get change from email message.') + chdict = src.parse(m)[1] self.assertEqual(chdict['category'], 'Test category') def test_CVSMaildirSource_create_change_with_no_comment(self): @@ -169,10 +157,7 @@ def test_CVSMaildirSource_create_change_with_no_comment(self): msg = cvs1_11_msg[:cvs1_11_msg.find('Commented out some stuff')] m = message_from_string(msg) src = CVSMaildirSource('/dev/null') - try: - chdict = src.parse(m)[1] - except: - self.fail('Failed to get change from email message.') + chdict = src.parse(m)[1] self.assertEqual(chdict['comments'], None) def test_CVSMaildirSource_create_change_with_no_files(self): @@ -180,38 +165,26 @@ def test_CVSMaildirSource_create_change_with_no_files(self): msg = cvs1_11_msg.replace('Files: base/module/src/make GNUmakefile,1.362,1.363', '') m = message_from_string(msg) src = CVSMaildirSource('/dev/null') - try: - chdict = src.parse(m) - except: - self.fail('Failed to get change from email message.') + chdict = src.parse(m) self.assertEqual(chdict, None) def test_CVSMaildirSource_create_change_with_no_project(self): msg = cvs1_11_msg.replace('Project: MyModuleName', '') m = message_from_string(msg) src = CVSMaildirSource('/dev/null') - try: - chdict = src.parse(m)[1] - except: - self.fail('Failed to get change from email message.') + chdict = src.parse(m)[1] self.assertEqual(chdict['project'], None) def test_CVSMaildirSource_create_change_with_no_repository(self): msg = cvs1_11_msg.replace('CVSROOT: :ext:cvshost.example.com:/cvsroot', '') m = message_from_string(msg) src = CVSMaildirSource('/dev/null') - try: - chdict = src.parse(m)[1] - except: - self.fail('Failed to get change from email message.') + chdict = src.parse(m)[1] self.assertEqual(chdict['repository'], None) def test_CVSMaildirSource_create_change_with_property(self): m = message_from_string(cvs1_11_msg) propDict = {'foo': 'bar'} src = CVSMaildirSource('/dev/null', properties=propDict) - try: - chdict = src.parse(m)[1] - except: - self.fail('Failed to get change from email message.') + chdict = src.parse(m)[1] self.assertEqual(chdict['properties']['foo'], 'bar') diff --git a/master/buildbot/test/unit/test_changes_svnpoller.py b/master/buildbot/test/unit/test_changes_svnpoller.py index 5a92e7baaca..d89a4647e5b 100644 --- a/master/buildbot/test/unit/test_changes_svnpoller.py +++ b/master/buildbot/test/unit/test_changes_svnpoller.py @@ -351,6 +351,20 @@ def test_get_new_logentries(self): self.assertEqual(s.last_change, 4) self.assertEqual(len(new), 0) + def test_get_text(self): + doc = xml.dom.minidom.parseString(""" + + + hi + 1 + 2 + + """.strip()) + s = self.attachSVNPoller('http://', split_file=split_file) + + self.assertEqual(s._get_text(doc, 'grandchild'), '1') + self.assertEqual(s._get_text(doc, 'nonexistent'), 'unknown') + def test_create_changes(self): base = ("file:///home/warner/stuff/Projects/Buildbot/trees/" + "svnpoller/_trial_temp/test_vc/repositories/SVN-Repository/sample") diff --git a/master/buildbot/test/unit/test_contrib_buildbot_cvs_mail.py b/master/buildbot/test/unit/test_contrib_buildbot_cvs_mail.py index 97a1045d9f9..0e254b0e476 100644 --- a/master/buildbot/test/unit/test_contrib_buildbot_cvs_mail.py +++ b/master/buildbot/test/unit/test_contrib_buildbot_cvs_mail.py @@ -133,7 +133,7 @@ def assertOutputOk(self, xxx_todo_changeme4, regexList): if not m: misses.append((regex, line)) self.assertEqual(misses, [], "got non-matching lines") - except: + except Exception: log.msg("got output:\n" + output) raise diff --git a/master/buildbot/test/unit/test_db_migrate_versions_019_merge_schedulers_to_objects.py b/master/buildbot/test/unit/test_db_migrate_versions_019_merge_schedulers_to_objects.py index 9e0b72104cd..313ecc76450 100644 --- a/master/buildbot/test/unit/test_db_migrate_versions_019_merge_schedulers_to_objects.py +++ b/master/buildbot/test/unit/test_db_migrate_versions_019_merge_schedulers_to_objects.py @@ -107,7 +107,7 @@ def verify_thd(conn): for tbl in 'schedulers', 'scheduler_upstream_buildsets': try: conn.execute("select * from %s" % tbl) - except: + except Exception: pass else: self.fail("%s table still exists" % tbl) diff --git a/master/buildbot/test/unit/test_db_migrate_versions_020_remove_change_links.py b/master/buildbot/test/unit/test_db_migrate_versions_020_remove_change_links.py index 5e6b5937914..b69d9838cf0 100644 --- a/master/buildbot/test/unit/test_db_migrate_versions_020_remove_change_links.py +++ b/master/buildbot/test/unit/test_db_migrate_versions_020_remove_change_links.py @@ -59,7 +59,7 @@ def verify_thd(conn): try: conn.execute("select * from change_links") - except: + except Exception: pass else: self.fail("change_links still exists") diff --git a/master/buildbot/test/unit/test_schedulers_manager.py b/master/buildbot/test/unit/test_schedulers_manager.py index 67ccadd31f0..1c831dfc78d 100644 --- a/master/buildbot/test/unit/test_schedulers_manager.py +++ b/master/buildbot/test/unit/test_schedulers_manager.py @@ -34,7 +34,7 @@ def getObjectId(sched_name, class_name): k = (sched_name, class_name) try: rv = self.objectids[k] - except: + except KeyError: rv = self.objectids[k] = self.next_objectid self.next_objectid += 1 return defer.succeed(rv) diff --git a/master/buildbot/test/unit/test_status_logfile.py b/master/buildbot/test/unit/test_status_logfile.py index d96879490c7..4fa08b21fdc 100644 --- a/master/buildbot/test/unit/test_status_logfile.py +++ b/master/buildbot/test/unit/test_status_logfile.py @@ -68,7 +68,7 @@ def tearDown(self): if self.logfile.openfile: try: self.logfile.openfile.close() - except: + except Exception: pass # oh well, we tried self.tearDownDirs() @@ -84,7 +84,7 @@ def delete_logfile(self): if self.logfile.openfile: try: self.logfile.openfile.close() - except: + except Exception: pass # oh well, we tried os.unlink(os.path.join('basedir', '123-stdio')) @@ -342,7 +342,7 @@ def tearDown(self): if self.logfile.openfile: try: self.logfile.openfile.close() - except: + except Exception: pass # oh well, we tried self.tearDownDirs() diff --git a/master/buildbot/test/util/db.py b/master/buildbot/test/util/db.py index f54471dfabc..70d112b311b 100644 --- a/master/buildbot/test/util/db.py +++ b/master/buildbot/test/util/db.py @@ -160,7 +160,7 @@ def thd(conn): tbl = model.Model.metadata.tables[row.table] try: tbl.insert(bind=conn).execute(row.values) - except: + except Exception: log.msg("while inserting %s - %s" % (row, row.values)) raise return self.db_pool.do(thd) diff --git a/master/buildbot/test/util/validation.py b/master/buildbot/test/util/validation.py index ec0359a68b9..f09297f0776 100644 --- a/master/buildbot/test/util/validation.py +++ b/master/buildbot/test/util/validation.py @@ -218,7 +218,7 @@ def validate(self, name, object): yield "%s[%s] source %r is not unicode" % (name, k, propsrc) try: json.dumps(propval) - except: + except (TypeError, ValueError): yield "%s[%r] value is not JSON-able" % (name, k) @@ -229,7 +229,7 @@ class JsonValidator(Validator): def validate(self, name, object): try: json.dumps(object) - except: + except (TypeError, ValueError): yield "%s[%r] value is not JSON-able" % (name, object) diff --git a/master/buildbot/util/croniter.py b/master/buildbot/util/croniter.py index 6d1f4a31fcc..a0d25ad9f6a 100644 --- a/master/buildbot/util/croniter.py +++ b/master/buildbot/util/croniter.py @@ -101,7 +101,7 @@ def __init__(self, expr_format, start_time=time()): try: t = int(t) - except: + except (ValueError, TypeError): pass if t in self.LOWMAP[i]: diff --git a/master/buildbot/util/eventual.py b/master/buildbot/util/eventual.py index 804c3ab8470..5061c50ff7a 100644 --- a/master/buildbot/util/eventual.py +++ b/master/buildbot/util/eventual.py @@ -46,7 +46,7 @@ def _turn(self): for cb, args, kwargs in events: try: cb(*args, **kwargs) - except: + except Exception: log.err() self._in_turn = False if self._events and not self._timer: diff --git a/master/buildbot/util/maildir.py b/master/buildbot/util/maildir.py index c49ae40c35a..93f402b6540 100644 --- a/master/buildbot/util/maildir.py +++ b/master/buildbot/util/maildir.py @@ -30,7 +30,7 @@ dnotify = None try: import dnotify -except: +except ImportError: log.msg("unable to import dnotify, so Maildir will use polling instead") @@ -118,7 +118,7 @@ def poll(self): for n in newfiles: try: yield self.messageReceived(n) - except: + except Exception: log.err(None, "while reading '%s' from maildir '%s':" % (n, self.basedir)) except Exception: log.err(None, "while polling maildir '%s':" % (self.basedir,)) diff --git a/master/buildbot/util/sautils.py b/master/buildbot/util/sautils.py index 507d44ebe26..02e9d9b4008 100644 --- a/master/buildbot/util/sautils.py +++ b/master/buildbot/util/sautils.py @@ -46,7 +46,7 @@ def sa_version(): def tryint(s): try: return int(s) - except: + except (ValueError, TypeError): return -1 return tuple(map(tryint, sa.__version__.split('.'))) return (0, 0, 0) # "it's old" diff --git a/master/buildbot/util/subscription.py b/master/buildbot/util/subscription.py index 5ade5d9266a..ee36df7e65c 100644 --- a/master/buildbot/util/subscription.py +++ b/master/buildbot/util/subscription.py @@ -35,7 +35,7 @@ def deliver(self, *args, **kwargs): for sub in list(self.subscriptions): try: sub.callback(*args, **kwargs) - except: + except Exception: log.err(failure.Failure(), 'while invoking callback %s to %s' % (sub.callback, self)) diff --git a/master/buildbot/www/resource.py b/master/buildbot/www/resource.py index 40255c7dab6..8792381636c 100644 --- a/master/buildbot/www/resource.py +++ b/master/buildbot/www/resource.py @@ -95,7 +95,7 @@ def fail(f): except Exception: try: request.finish() - except: + except Exception: pass return server.NOT_DONE_YET diff --git a/master/contrib/SimpleConfig.py b/master/contrib/SimpleConfig.py index 4cd4d45b0b7..eeaa5545bcb 100644 --- a/master/contrib/SimpleConfig.py +++ b/master/contrib/SimpleConfig.py @@ -176,7 +176,7 @@ def __init__(self, thisfile = thisfile.replace(".pyc", ".py") try: thisfile = os.readlink(thisfile) - except: + except OSError: pass dir = os.path.join(os.path.dirname(thisfile)) @@ -210,7 +210,7 @@ def __init__(self, self.__auth = auth.BasicAuth([(s["webuser"].encode('ascii', 'ignore'), s["webpass"].encode('ascii', 'ignore'))]) # For the moment, all slaves have same password self.slavepass = s["slavepass"].encode('ascii', 'ignore') - except: + except Exception: exit("%s must be a json file containing webuser, webpass, and slavepass; ascii only, no commas in quotes" % secretsfile) # STATUS TARGETS diff --git a/master/contrib/buildbot_cvs_mail.py b/master/contrib/buildbot_cvs_mail.py index 554686c03d3..dd623773069 100755 --- a/master/contrib/buildbot_cvs_mail.py +++ b/master/contrib/buildbot_cvs_mail.py @@ -41,7 +41,7 @@ try: import pwd -except: +except ImportError: # pwd is not available on Windows.. pwd = None diff --git a/master/contrib/bzr_buildbot.py b/master/contrib/bzr_buildbot.py index 39186d00428..9f8918358c5 100644 --- a/master/contrib/bzr_buildbot.py +++ b/master/contrib/bzr_buildbot.py @@ -254,7 +254,7 @@ def poll(self): self.getRawChanges) except (SystemExit, KeyboardInterrupt): raise - except: + except Exception: # we'll try again next poll. Meanwhile, let's report. twisted.python.log.err() else: @@ -347,7 +347,7 @@ def _putResultInDeferred(reactor, deferred, f, args, kwargs): """ try: result = f(*args, **kwargs) - except: + except Exception: f = failure.Failure() reactor.callFromThread(deferred.errback, f) else: diff --git a/master/contrib/check_buildbot.py b/master/contrib/check_buildbot.py index e8100976aa7..8a709dbbc36 100755 --- a/master/contrib/check_buildbot.py +++ b/master/contrib/check_buildbot.py @@ -53,12 +53,12 @@ def main(): try: data = urllib.urlopen(url).read() - except: + except Exception: exit(CRITICAL, "Error connecting to %s" % url) try: data = json.loads(data) - except: + except ValueError: exit(CRITICAL, "Could not parse output of %s as json" % url) if not data: @@ -73,7 +73,7 @@ def main(): try: alarm_code = STATUS_CODES[alarm_state[0]] - except: + except (KeyError, IndexError): status = UNKNOWN messages.append("%s has unknown alarm state %s" % (alarm_name, alarm_state)) continue diff --git a/master/contrib/coverage2text.py b/master/contrib/coverage2text.py index 6f731f0f913..91247311a93 100755 --- a/master/contrib/coverage2text.py +++ b/master/contrib/coverage2text.py @@ -84,9 +84,7 @@ def report(self, outfile=None, sortby="uncovered"): sortkey = cu.name lines.append((sortkey, fmt_coverage % args)) total += nums - except KeyboardInterrupt: # pragma: no cover - raise - except: + except Exception: if not self.ignore_errors: typ, msg = sys.exc_info()[:2] outfile.write(fmt_err % (cu.name, typ.__name__, msg)) diff --git a/master/contrib/git_buildbot.py b/master/contrib/git_buildbot.py index 5eb4b1e6aa7..25747dcffa8 100755 --- a/master/contrib/git_buildbot.py +++ b/master/contrib/git_buildbot.py @@ -453,8 +453,6 @@ def parse_options(): process_changes() send_changes() -except SystemExit: - pass -except: +except Exception: logging.exception("Unhandled exception") sys.exit(1) diff --git a/master/contrib/googlecode_atom.py b/master/contrib/googlecode_atom.py index b129765a68c..58b879c21a8 100644 --- a/master/contrib/googlecode_atom.py +++ b/master/contrib/googlecode_atom.py @@ -156,7 +156,7 @@ def _parse_changes(self, query): d["files"] = [f.strip() for f in d["files"]] try: d["comments"] = content[1].encode("ascii", "replace") - except: + except Exception: d["comments"] = "No commit message provided" changes.append(d) diff --git a/master/contrib/run_maxq.py b/master/contrib/run_maxq.py index f7e2b8e55cc..b2b12ff9313 100755 --- a/master/contrib/run_maxq.py +++ b/master/contrib/run_maxq.py @@ -39,7 +39,7 @@ try: execfile(test, globals().copy()) - except: + except Exception: ei = sys.exc_info() print "TEST FAILURE:", ei[1] diff --git a/master/contrib/svnpoller.py b/master/contrib/svnpoller.py index 26a456bece0..f216bfe8be1 100755 --- a/master/contrib/svnpoller.py +++ b/master/contrib/svnpoller.py @@ -63,7 +63,7 @@ try: ini.read(fname) -except: +except Exception: print "Creating changemonitor config.ini:", fname ini.add_section("CurrentRevision") ini.set("CurrentRevision", -1) @@ -95,5 +95,5 @@ f = open(fname, "w") ini.write(f) # print "WROTE CHANGES TO",fname - except: + except Exception: print "FAILED TO RECORD INI FILE" diff --git a/master/docs/manual/optimization.rst b/master/docs/manual/optimization.rst index f4156e6d972..444365b4e67 100644 --- a/master/docs/manual/optimization.rst +++ b/master/docs/manual/optimization.rst @@ -19,7 +19,7 @@ For example, if most of your build properties are strings, you can gain an appro m = my_regexp.match(str) try: return list(m.groups()) - except: + except Exception: return original_decode(str, *args, **kw) json._default_decoder.decode = decode_with_re diff --git a/slave/buildslave/bot.py b/slave/buildslave/bot.py index 67a5d86544c..98180caf2d4 100644 --- a/slave/buildslave/bot.py +++ b/slave/buildslave/bot.py @@ -381,7 +381,7 @@ def gotPerspective(self, perspective): self.perspective = perspective try: perspective.broker.transport.setTcpKeepAlive(1) - except: + except Exception: log.msg("unable to set SO_KEEPALIVE") if not self.keepaliveInterval: self.keepaliveInterval = 10 * 60 @@ -516,7 +516,7 @@ def recordHostname(self, basedir): try: open(filename, "w").write("%s\n" % hostname) - except: + except Exception: log.msg("failed - ignoring") def _handleSIGHUP(self, *args): diff --git a/slave/buildslave/commands/base.py b/slave/buildslave/commands/base.py index 5793a5b3db9..1592498ad3a 100644 --- a/slave/buildslave/commands/base.py +++ b/slave/buildslave/commands/base.py @@ -621,7 +621,7 @@ def doPatch(self, res): def cleanup(x): try: os.unlink(os.path.join(dir, ".buildbot-diff")) - except: + except OSError: pass return x d.addBoth(cleanup) diff --git a/slave/buildslave/commands/bk.py b/slave/buildslave/commands/bk.py index 3d00a83f060..9efc1b3e668 100644 --- a/slave/buildslave/commands/bk.py +++ b/slave/buildslave/commands/bk.py @@ -102,14 +102,6 @@ def parseGotRevision(self): d = c.start() def _parse(res): - r_raw = c.stdout.strip() - try: - r = r_raw - except: - msg = ("BK.parseGotRevision unable to parse output: (%s)" % r_raw) - log.msg(msg) - self.sendStatus({'header': msg + "\n"}) - raise ValueError(msg) - return r + return c.stdout.strip() d.addCallback(_parse) return d diff --git a/slave/buildslave/commands/transfer.py b/slave/buildslave/commands/transfer.py index 8d21423a1bd..977b3b552c3 100644 --- a/slave/buildslave/commands/transfer.py +++ b/slave/buildslave/commands/transfer.py @@ -91,7 +91,7 @@ def start(self): self.fp = open(self.path, 'rb') if self.debug: log.msg("Opened '%s' for upload" % self.path) - except: + except Exception: self.fp = None self.stderr = "Cannot open file '%s' for upload" % self.path self.rc = 1 diff --git a/slave/buildslave/commands/utils.py b/slave/buildslave/commands/utils.py index 8a69e262a6f..58d42f56bdf 100644 --- a/slave/buildslave/commands/utils.py +++ b/slave/buildslave/commands/utils.py @@ -63,7 +63,7 @@ def rmdirRecursive(dir): if not isinstance(dir, unicode): try: dir = unicode(dir, "utf-8") - except: + except UnicodeDecodeError: log.err("rmdirRecursive: decoding from UTF-8 failed (ignoring)") try: diff --git a/slave/buildslave/monkeypatches/bug4881.py b/slave/buildslave/monkeypatches/bug4881.py index 56acce98096..d86a97f8a8f 100644 --- a/slave/buildslave/monkeypatches/bug4881.py +++ b/slave/buildslave/monkeypatches/bug4881.py @@ -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): diff --git a/slave/buildslave/runprocess.py b/slave/buildslave/runprocess.py index 7d35eb15f1c..40b160e38cb 100644 --- a/slave/buildslave/runprocess.py +++ b/slave/buildslave/runprocess.py @@ -424,9 +424,8 @@ def start(self): self.deferred = defer.Deferred() try: self._startCommand() - except: - log.msg("error in RunProcess._startCommand") - log.err() + except Exception: + log.err("error in RunProcess._startCommand") self._addToBuffers('stderr', "error in RunProcess._startCommand\n") self._addToBuffers('stderr', traceback.format_exc()) self._sendBuffers() diff --git a/slave/buildslave/scripts/stop.py b/slave/buildslave/scripts/stop.py index 199b774c7ce..24dfaf605d1 100644 --- a/slave/buildslave/scripts/stop.py +++ b/slave/buildslave/scripts/stop.py @@ -44,7 +44,7 @@ def stopSlave(basedir, quiet, signame="TERM"): os.chdir(basedir) try: f = open("twistd.pid", "rt") - except: + except IOError: raise SlaveNotRunning() pid = int(f.read().strip()) diff --git a/slave/buildslave/test/unit/test_commands_utils.py b/slave/buildslave/test/unit/test_commands_utils.py index 1938b6754cb..d820bdfdafd 100644 --- a/slave/buildslave/test/unit/test_commands_utils.py +++ b/slave/buildslave/test/unit/test_commands_utils.py @@ -90,7 +90,7 @@ def setUp(self): try: if os.path.exists(self.target): shutil.rmtree(self.target) - except: + except Exception: # this test will probably fail anyway e = sys.exc_info()[0] raise unittest.SkipTest("could not clean before test: %s" % (e,)) @@ -107,7 +107,7 @@ def tearDown(self): try: if os.path.exists(self.target): shutil.rmtree(self.target) - except: + except Exception: print "\n(target directory was not removed by test, and cleanup failed too)\n" raise diff --git a/slave/buildslave/test/unit/test_runprocess.py b/slave/buildslave/test/unit/test_runprocess.py index 9b5e7248c6f..3e8bf80fc56 100644 --- a/slave/buildslave/test/unit/test_runprocess.py +++ b/slave/buildslave/test/unit/test_runprocess.py @@ -523,7 +523,7 @@ def poll(): if os.path.exists(pidfile): try: pid = int(open(pidfile).read()) - except: + except (IOError, TypeError, ValueError): pid = None if pid is not None: diff --git a/slave/buildslave/test/util/command.py b/slave/buildslave/test/util/command.py index 23760b6d62e..d0eb7688ec0 100644 --- a/slave/buildslave/test/util/command.py +++ b/slave/buildslave/test/util/command.py @@ -111,7 +111,7 @@ def assertUpdates(self, updates, msg=None): try: if "elapsed" in update: continue - except: + except Exception: pass my_updates.append(update) self.assertEqual(my_updates, updates, msg)