use Exception instead of BaseException for bare expection

This commit is contained in:
Yuming Zhu 2020-03-02 18:27:24 +08:00
parent b3b0c8d51e
commit cf34706f04
21 changed files with 70 additions and 70 deletions

View file

@ -167,7 +167,7 @@ def main(options, session):
break
except koji.RetryError:
raise
except BaseException:
except Exception:
# XXX - this is a little extreme
# log the exception and continue
logger.error(''.join(traceback.format_exception(*sys.exc_info())))
@ -488,7 +488,7 @@ class BuildRoot(object):
fd.close()
fd = open(fpath, 'rb')
logs[fname] = (fd, stat_info.st_ino, stat_info.st_size or size, fpath)
except BaseException:
except Exception:
self.logger.error("Error reading mock log: %s", fpath)
self.logger.error(''.join(traceback.format_exception(*sys.exc_info())))
continue
@ -533,7 +533,7 @@ class BuildRoot(object):
os.setregid(gid, gid)
os.setreuid(uid, uid)
os.execvp(cmd[0], cmd)
except BaseException:
except Exception:
# diediedie
print("Failed to exec mock")
print(''.join(traceback.format_exception(*sys.exc_info())))
@ -801,7 +801,7 @@ class BuildRoot(object):
with koji.openRemoteFile(repomdpath, **opts) as fo:
try:
repodata = repoMDObject.RepoMD('ourrepo', fo)
except BaseException:
except Exception:
raise koji.BuildError("Unable to parse repomd.xml file for %s" %
os.path.join(repodir, self.br_arch))
data = repodata.getData('origin')
@ -1061,7 +1061,7 @@ class BuildTask(BaseTaskHandler):
except (SystemExit, ServerExit, KeyboardInterrupt):
# we do not trap these
raise
except BaseException:
except Exception:
if not self.opts.get('scratch'):
# scratch builds do not get imported
self.session.host.failBuild(self.id, build_id)
@ -1547,7 +1547,7 @@ class MavenTask(MultiPlatformTask):
except (SystemExit, ServerExit, KeyboardInterrupt):
# we do not trap these
raise
except BaseException:
except Exception:
if not self.opts.get('scratch'):
# scratch builds do not get imported
self.session.host.failBuild(self.id, self.build_id)
@ -2067,7 +2067,7 @@ class WrapperRPMTask(BaseBuildTask):
buildroot.build(srpm)
except (SystemExit, ServerExit, KeyboardInterrupt):
raise
except BaseException:
except Exception:
if self.new_build_id:
self.session.host.failBuild(self.id, self.new_build_id)
raise
@ -2111,7 +2111,7 @@ class WrapperRPMTask(BaseBuildTask):
self.uploadFile(os.path.join(resultdir, rpm_fn))
except (SystemExit, ServerExit, KeyboardInterrupt):
raise
except BaseException:
except Exception:
if self.new_build_id:
self.session.host.failBuild(self.id, self.new_build_id)
raise
@ -2140,7 +2140,7 @@ class WrapperRPMTask(BaseBuildTask):
{'noarch': rellogs})
except (SystemExit, ServerExit, KeyboardInterrupt):
raise
except BaseException:
except Exception:
self.session.host.failBuild(self.id, self.new_build_id)
raise
if not opts.get('skip_tag'):
@ -2540,7 +2540,7 @@ class BuildBaseImageTask(BuildImageTask):
except (SystemExit, ServerExit, KeyboardInterrupt):
# we do not trap these
raise
except BaseException:
except Exception:
if not opts.get('scratch'):
# scratch builds do not get imported
if bld_info:
@ -2631,7 +2631,7 @@ class BuildApplianceTask(BuildImageTask):
except (SystemExit, ServerExit, KeyboardInterrupt):
# we do not trap these
raise
except BaseException:
except Exception:
if not opts.get('scratch'):
# scratch builds do not get imported
if bld_info:
@ -2718,7 +2718,7 @@ class BuildLiveCDTask(BuildImageTask):
except (SystemExit, ServerExit, KeyboardInterrupt):
# we do not trap these
raise
except BaseException:
except Exception:
if not opts.get('scratch'):
# scratch builds do not get imported
if bld_info:
@ -2857,7 +2857,7 @@ class BuildLiveMediaTask(BuildImageTask):
except (SystemExit, ServerExit, KeyboardInterrupt):
# we do not trap these
raise
except BaseException:
except Exception:
if not opts.get('scratch'):
# scratch builds do not get imported
if bld_info:
@ -4656,7 +4656,7 @@ class BuildIndirectionImageTask(OzImageTask):
return self._do_indirection(opts, base_factory_image, utility_factory_image,
indirection_template, tlog, ozlog, fhandler,
bld_info, target_info, bd)
except BaseException:
except Exception:
if not opts.get('scratch'):
# scratch builds do not get imported
if bld_info:
@ -5129,7 +5129,7 @@ Build Info: %(weburl)s/buildinfo?buildID=%(build_id)i\r
result = None
try:
result = self.session.getTaskResult(task_id)
except BaseException:
except Exception:
excClass, result = sys.exc_info()[:2]
if hasattr(result, 'faultString'):
result = result.faultString

View file

@ -337,7 +337,7 @@ if __name__ == "__main__":
rv = 0
except (KeyboardInterrupt, SystemExit):
rv = 1
except BaseException:
except Exception:
if options.debug:
raise
else:
@ -346,6 +346,6 @@ if __name__ == "__main__":
logger.error("%s: %s" % (exctype.__name__, value))
try:
session.logout()
except BaseException:
except Exception:
pass
sys.exit(rv)

View file

@ -3056,7 +3056,7 @@ def anon_handle_list_builds(goptions, session, args):
dt = dateutil.parser.parse(val)
ts = time.mktime(dt.timetuple())
setattr(options, opt, ts)
except BaseException:
except Exception:
parser.error(_("Invalid time specification: %s") % val)
if options.before:
opts['completeBefore'] = getattr(options, 'before')
@ -4450,7 +4450,7 @@ def anon_handle_list_history(goptions, session, args):
dt = dateutil.parser.parse(val)
ts = time.mktime(dt.timetuple())
setattr(options, opt, ts)
except BaseException:
except Exception:
parser.error(_("Invalid time specification: %s") % val)
for opt in ('package', 'tag', 'build', 'editor', 'user', 'permission',
'cg', 'external_repo', 'build_target', 'group', 'before',

View file

@ -2672,7 +2672,7 @@ def repo_init(tag, with_src=False, with_debuginfo=False, event=None, with_separa
relpath = os.path.relpath(srcdir, dest_parent)
try:
os.symlink(relpath, destlink)
except BaseException:
except Exception:
log_error('Error linking %s to %s' % (destlink, relpath))
for artifact_dir, artifacts in six.iteritems(artifact_dirs):
_write_maven_repo_metadata(artifact_dir, artifacts)
@ -4989,7 +4989,7 @@ def list_task_output(taskID, stat=False, all_volumes=False, strict=False):
# raise error if task doesn't exist
try:
Task(taskID).getInfo(strict=True)
except BaseException:
except Exception:
raise koji.GenericError("Task doesn't exist")
if stat or all_volumes:
@ -7375,10 +7375,10 @@ def check_rpm_sig(an_rpm, sigkey, sighdr):
ts.setVSFlags(0) # full verify
with open(temp, 'rb') as fo:
hdr = ts.hdrFromFdno(fo.fileno())
except BaseException:
except Exception:
try:
os.unlink(temp)
except BaseException:
except Exception:
pass
raise
raw_key = koji.get_header_field(hdr, 'siggpg')

View file

@ -242,7 +242,7 @@ class ModXMLRPCRequestHandler(object):
except Fault as fault:
self.traceback = True
response = dumps(fault, marshaller=Marshaller)
except BaseException:
except Exception:
self.traceback = True
# report exception back to server
e_class, e = sys.exc_info()[:2]

View file

@ -303,10 +303,10 @@ class GenericError(Exception):
def __str__(self):
try:
return str(self.args[0]['args'][0])
except BaseException:
except Exception:
try:
return str(self.args[0])
except BaseException:
except Exception:
return str(self.__dict__)
# END kojikamid dup #
@ -1730,7 +1730,7 @@ def format_exc_plus():
# COULD cause any exception, so we MUST catch any...:
try:
rv += "%s\n" % value
except BaseException:
except Exception:
rv += "<ERROR WHILE PRINTING VALUE>\n"
return rv
@ -2273,7 +2273,7 @@ class VirtualMethod(object):
self.__session._apidoc = dict(
[(f["name"], f) for f in self.__func("_listapi", [], {})]
)
except BaseException:
except Exception:
self.__session._apidoc = {}
funcdoc = self.__session._apidoc.get(self.__name)
@ -2659,7 +2659,7 @@ class ClientSession(object):
if self.__dict__:
try:
self.logout()
except BaseException:
except Exception:
pass
def callMethod(self, name, *args, **opts):
@ -3303,7 +3303,7 @@ class DBHandler(logging.Handler):
# self.cnx.commit()
# XXX - committing here is most likely wrong, but we need to set commit_pending or
# something...and this is really the wrong place for that
except BaseException:
except Exception:
self.handleError(record)

View file

@ -238,7 +238,7 @@ def _try_read_cpuinfo():
mounted). """
try:
return open("/proc/cpuinfo", "r")
except BaseException:
except Exception:
return []
@ -248,7 +248,7 @@ def _parse_auxv():
# In case we can't open and read /proc/self/auxv, just return
try:
data = open("/proc/self/auxv", "rb").read()
except BaseException:
except Exception:
return
# Define values from /usr/include/elf.h
@ -323,7 +323,7 @@ def getCanonPPCArch(arch):
try:
if platform.startswith("power") and int(platform[5:].rstrip('+')) >= 7:
return "ppc64p7"
except BaseException:
except Exception:
pass
if machine is None:
@ -388,7 +388,7 @@ def getCanonArch(skipRpmPlatform=0):
f.close()
(arch, vendor, opersys) = line.split("-", 2)
return arch
except BaseException:
except Exception:
pass
arch = os.uname()[4]

View file

@ -95,7 +95,7 @@ class Session(object):
raise koji.AuthError('%s not specified in session args' % field)
try:
callnum = args['callnum'][0]
except BaseException:
except Exception:
callnum = None
# lookup the session
c = context.cnx.cursor()

View file

@ -139,7 +139,7 @@ def log_output(session, path, args, outfile, uploadpath, cwd=None, logerror=0, a
if env:
environ.update(env)
os.execvpe(path, args, environ)
except BaseException:
except Exception:
msg = ''.join(traceback.format_exception(*sys.exc_info()))
if fd:
try:
@ -148,7 +148,7 @@ def log_output(session, path, args, outfile, uploadpath, cwd=None, logerror=0, a
else:
os.write(fd, msg)
os.close(fd)
except BaseException:
except Exception:
pass
print(msg)
os._exit(1)
@ -167,7 +167,7 @@ def log_output(session, path, args, outfile, uploadpath, cwd=None, logerror=0, a
except IOError:
# will happen if the forked process has not created the logfile yet
continue
except BaseException:
except Exception:
print('Error reading log file: %s' % outfile)
print(''.join(traceback.format_exception(*sys.exc_info())))
@ -1163,7 +1163,7 @@ class TaskManager(object):
try:
self.session.logoutChild(session_id)
del self.subsessions[task_id]
except BaseException:
except Exception:
# not much we can do about it
pass
if wait:
@ -1266,7 +1266,7 @@ class TaskManager(object):
valid_host = handler.checkHost(self.hostdata)
except (SystemExit, KeyboardInterrupt):
raise
except BaseException:
except Exception:
valid_host = False
self.logger.warn('Error during host check')
self.logger.warn(''.join(traceback.format_exception(*sys.exc_info())))
@ -1350,7 +1350,7 @@ class TaskManager(object):
# freeing this task will allow the pending restart to take effect
self.session.host.freeTasks([handler.id])
return
except BaseException:
except Exception:
tb = ''.join(traceback.format_exception(*sys.exc_info()))
self.logger.warn("TRACEBACK: %s" % tb)
# report exception back to server

View file

@ -199,7 +199,7 @@ def run_callbacks(cbtype, *args, **kws):
cb_args, cb_kwargs = _fix_cb_args(func, args, kws, cache)
try:
func(cbtype, *cb_args, **cb_kwargs)
except BaseException:
except Exception:
msg = 'Error running %s callback from %s' % (cbtype, func.__module__)
if getattr(func, 'failure_is_an_option', False):
logging.getLogger('koji.plugin').warn(msg, exc_info=True)

View file

@ -71,7 +71,7 @@ class Rpmdiff:
except AttributeError:
try:
PREREQ_FLAG = rpm.RPMSENSE_PREREQ
except BaseException:
except Exception:
# (proyvind): This seems ugly, but then again so does
# this whole check as well.
PREREQ_FLAG = False

View file

@ -79,7 +79,7 @@ def safe_rmtree(path, unmount=False, strict=True):
logger.debug("Removing: %s" % path)
try:
os.remove(path)
except BaseException:
except Exception:
if strict:
raise
else:

View file

@ -451,7 +451,7 @@ Build: %%(name)s-%%(version)s-%%(release)s
s.login(options.smtp_user, options.smtp_pass)
s.sendmail(msg['From'], msg['To'], msg.as_string())
s.quit()
except BaseException:
except Exception:
print("FAILED: Sending warning notice to %s" % msg['To'])
@ -1010,7 +1010,7 @@ if __name__ == "__main__":
if options.exit_on_lock:
try:
session.logout()
except BaseException:
except Exception:
pass
sys.exit(1)
os.close(lock_fd)
@ -1041,7 +1041,7 @@ if __name__ == "__main__":
# print("%s: %s" % (exctype, value))
try:
session.logout()
except BaseException:
except Exception:
pass
if not options.skip_main:
sys.exit(rv)

View file

@ -454,7 +454,7 @@ class TrackedBuild(object):
# XXX - Move SCM class out of kojid and use it to check for scm url
if src.startswith('cvs:'):
return src
except BaseException:
except Exception:
pass
# otherwise fail
return None
@ -1286,7 +1286,7 @@ def main(args):
filename = options.logfile
try:
logfile = os.open(filename, os.O_CREAT | os.O_RDWR | os.O_APPEND, 0o777)
except BaseException:
except Exception:
logfile = None
if logfile is not None:
log("logging to %s" % filename)
@ -1341,6 +1341,6 @@ if __name__ == "__main__":
# log ("%s: %s" % (exctype, value))
try:
session.logout()
except BaseException:
except Exception:
pass
sys.exit(rv)

View file

@ -76,7 +76,7 @@ def clean_scratch_tasks(cursor, vacuum, test, age):
if opts['scratch']:
cursor.execute("INSERT INTO temp_scratch_tasks VALUES (%s)", (task_id,))
ids.append(task_id)
except BaseException:
except Exception:
continue
parents = ids

View file

@ -410,7 +410,7 @@ class RepoManager(object):
while True:
self.checkCurrentRepos()
time.sleep(self.options.sleeptime)
except BaseException:
except Exception:
self.logger.exception('Error in currency checker thread')
raise
finally:
@ -425,7 +425,7 @@ class RepoManager(object):
while True:
self.regenRepos()
time.sleep(self.options.sleeptime)
except BaseException:
except Exception:
self.logger.exception('Error in regen thread')
raise
finally:
@ -856,7 +856,7 @@ def main(options, session):
except SystemExit:
logger.warn("Shutting down")
break
except BaseException:
except Exception:
# log the exception and continue
logger.error(''.join(traceback.format_exception(*sys.exc_info())))
try:
@ -1005,7 +1005,7 @@ if __name__ == "__main__":
try:
logfile = open(options.logfile, "w")
logfile.close()
except BaseException:
except Exception:
sys.stderr.write("Cannot create logfile: %s\n" % options.logfile)
sys.exit(1)
if not os.access(options.logfile, os.W_OK):

View file

@ -699,7 +699,7 @@ def stream_logs(server, handler, builds):
try:
fd = open(log, 'r')
logs[log] = (relpath, fd)
except BaseException:
except Exception:
log_local('Error opening %s' % log)
continue
else:
@ -713,7 +713,7 @@ def stream_logs(server, handler, builds):
del contents
try:
server.uploadDirect(relpath, offset, size, digest, data)
except BaseException:
except Exception:
log_local('error uploading %s' % relpath)
time.sleep(1)
@ -729,14 +729,14 @@ def fail(server, handler):
logfd.flush()
upload_file(server, os.path.dirname(logfile),
os.path.basename(logfile))
except BaseException:
except Exception:
log_local('error calling upload_file()')
while True:
try:
# this is the very last thing we do, keep trying as long as we can
server.failTask(tb)
break
except BaseException:
except Exception:
log_local('error calling server.failTask()')
sys.exit(1)
@ -806,7 +806,7 @@ def main():
results['logs'].append(os.path.basename(logfile))
server.closeTask(results)
except BaseException:
except Exception:
fail(server, handler)
sys.exit(0)

View file

@ -241,7 +241,7 @@ def main(options, session):
break
except koji.RetryError:
raise
except BaseException:
except Exception:
# XXX - this is a little extreme
# log the exception and continue
logger.error('Error in main loop', exc_info=True)
@ -295,7 +295,7 @@ class DaemonXMLRPCServer(six.moves.xmlrpc_server.SimpleXMLRPCServer):
self.close_request(conn)
except socket.timeout:
pass
except BaseException:
except Exception:
self.logger.error('Error handling requests', exc_info=True)
if sys.version_info[:2] <= (2, 4):
@ -313,7 +313,7 @@ class DaemonXMLRPCServer(six.moves.xmlrpc_server.SimpleXMLRPCServer):
methodresponse=1, allow_none=True)
except six.moves.xmlrpc_client.Fault as fault:
response = six.moves.xmlrpc_client.dumps(fault)
except BaseException:
except Exception:
# report exception back to server
response = six.moves.xmlrpc_client.dumps(
six.moves.xmlrpc_client.Fault(
@ -415,7 +415,7 @@ class WinBuildTask(MultiPlatformTask):
except (SystemExit, ServerExit, KeyboardInterrupt):
# we do not trap these
raise
except BaseException:
except Exception:
if not opts.get('scratch'):
# scratch builds do not get imported
self.session.host.failBuild(self.id, build_id)
@ -1056,7 +1056,7 @@ class VMTaskManager(TaskManager):
if os.path.isfile(disk):
os.unlink(disk)
self.logger.debug('Removed disk file %s for VM %s', disk, vm_name)
except BaseException:
except Exception:
self.logger.error('Error removing disk file %s for VM %s', disk, vm_name,
exc_info=True)
return False

View file

@ -714,7 +714,7 @@ def taskinfo(environ, taskID):
if task['state'] in (koji.TASK_STATES['CLOSED'], koji.TASK_STATES['FAILED']):
try:
result = server.getTaskResult(task['id'])
except BaseException:
except Exception:
excClass, exc = sys.exc_info()[:2]
values['result'] = exc
values['excClass'] = excClass
@ -748,7 +748,7 @@ def taskinfo(environ, taskID):
try:
values['params_parsed'] = _genHTML(environ, 'taskinfo_params.chtml')
except BaseException:
except Exception:
values['params_parsed'] = None
return _genHTML(environ, 'taskinfo.chtml')
@ -2458,7 +2458,7 @@ def search(environ, start=None, order=None):
if match == 'regexp':
try:
re.compile(terms)
except BaseException:
except Exception:
values['error'] = 'Invalid regular expression'
return _genHTML(environ, 'search.chtml')

View file

@ -207,7 +207,7 @@ class Dispatcher(object):
args = inspect.getargspec(val)
if not args[0] or args[0][0] != 'environ':
continue
except BaseException:
except Exception:
tb_str = ''.join(traceback.format_exception(*sys.exc_info()))
self.logger.error(tb_str)
self.handler_index[name] = val

View file

@ -45,7 +45,7 @@ class NoSuchException(Exception):
try:
# pyOpenSSL might not be around
from OpenSSL.SSL import Error as SSL_Error
except BaseException:
except Exception:
SSL_Error = NoSuchException