Use Py3-compatible exception handling

In once case we can completely drop try-except statements: it only
logs the exception details but that will be logged again anyway.

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2017-08-24 14:49:08 +02:00
parent ec39514fba
commit 439a7ce348
3 changed files with 5 additions and 9 deletions

View File

@ -238,11 +238,7 @@ def main():
notifier=notifier)
notifier.compose = compose
COMPOSE = compose
try:
run_compose(compose, create_latest_link=create_latest_link, latest_link_status=latest_link_status)
except Exception, ex:
compose.log_error("Compose run failed: %s" % ex)
raise
run_compose(compose, create_latest_link=create_latest_link, latest_link_status=latest_link_status)
def run_compose(compose, create_latest_link=True, latest_link_status=None):
@ -455,7 +451,7 @@ if __name__ == "__main__":
except (Exception, KeyboardInterrupt) as ex:
if COMPOSE:
tb_path = COMPOSE.paths.log.log_file("global", "traceback")
COMPOSE.log_error("Exception: %s" % ex)
COMPOSE.log_error("Compose run failed: %s" % ex)
COMPOSE.log_error("Extended traceback in: %s" % tb_path)
COMPOSE.log_critical("Compose failed: %s" % COMPOSE.topdir)
COMPOSE.write_status("DOOMED")

View File

@ -663,7 +663,7 @@ class Pungi(PungiBase):
self.add_package(dep, msg)
added.add(dep)
except (yum.Errors.InstallError, yum.Errors.YumBaseError), ex:
except (yum.Errors.InstallError, yum.Errors.YumBaseError) as ex:
self.logger.warn("Unresolvable dependency %s in %s.%s (repo: %s)" % (r, po.name, po.arch, po.repoid))
continue
self.resolved_deps[req] = None

View File

@ -68,7 +68,7 @@ def _link(local, target, logger, force=False):
try:
os.link(local, target)
except OSError, e:
except OSError as e:
if e.errno != 18: # EXDEV
logger.error('Got an error linking from cache: %s' % e)
raise OSError(e)
@ -129,7 +129,7 @@ def _doCheckSum(path, hash, logger):
# Try to open the file, using binary flag.
try:
myfile = open(path, 'rb')
except IOError, e:
except IOError as e:
logger.error("Could not open file %s: %s" % (path, e))
return False