From: Mike Frysinger <vapier@gentoo.org>
To: gentoo-catalyst@lists.gentoo.org
Subject: [gentoo-catalyst] [PATCH 05/13] lint: clean up bare exception handling
Date: Tue, 6 Oct 2015 11:05:21 -0400 [thread overview]
Message-ID: <1444143929-26705-5-git-send-email-vapier@gentoo.org> (raw)
In-Reply-To: <1444143929-26705-1-git-send-email-vapier@gentoo.org>
It's a bad idea to use a bare except clause as you end up including
things like SystemExit, KeyboardInterrupt, and GeneratorExit, none
of which we actually want to catch. Some of the cases in the code
were explicitly catching & passing SystemExit back up which proves
this point.
---
catalyst/base/stagebase.py | 2 +-
catalyst/lock.py | 26 ++++----------------------
catalyst/main.py | 2 +-
catalyst/support.py | 15 +++++----------
targets/stage1/build.py | 2 +-
5 files changed, 12 insertions(+), 35 deletions(-)
diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 409fcab..e393c5b 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -1015,7 +1015,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
target is fully initialized
"""
self.snapshot_lock_object.unlock()
- except:
+ except Exception:
pass
if ouch:
"""
diff --git a/catalyst/lock.py b/catalyst/lock.py
index 01b1aa8..d6653f7 100644
--- a/catalyst/lock.py
+++ b/catalyst/lock.py
@@ -130,8 +130,6 @@ class LockDir(object):
try:
if os.stat(self.lockfile).st_gid != self.gid:
os.chown(self.lockfile,os.getuid(),self.gid)
- except SystemExit, e:
- raise
except OSError, e:
if e[0] == 2: #XXX: No such file or directory
return self.fcntl_locking(locktype)
@@ -185,7 +183,7 @@ class LockDir(object):
try:
os.close(self.myfd)
self.myfd=None
- except:
+ except Exception:
pass
return False
@@ -194,8 +192,6 @@ class LockDir(object):
self.myfd = os.open(self.lockfile, os.O_WRONLY,0660)
unlinkfile = 1
self.locking_method(self.myfd,fcntl.LOCK_UN)
- except SystemExit, e:
- raise e
except Exception, e:
#if self.myfd is not None:
#print "fcntl_unlock() trying to close", self.myfd
@@ -213,7 +209,7 @@ class LockDir(object):
InUse=False
try:
self.locking_method(self.myfd,fcntl.LOCK_EX|fcntl.LOCK_NB)
- except:
+ except Exception:
print "Read lock may be in effect. skipping lockfile delete..."
InUse=True
# We won the lock, so there isn't competition for it.
@@ -227,8 +223,6 @@ class LockDir(object):
self.myfd=None
# if "DEBUG" in self.settings:
# print "Unlinked lockfile..."
- except SystemExit, e:
- raise e
except Exception, e:
# We really don't care... Someone else has the lock.
# So it is their problem now.
@@ -273,8 +267,6 @@ class LockDir(object):
print_traceback=True)
try:
os.link(self.myhardlock, self.lockfile)
- except SystemExit:
- raise
except Exception:
# if "DEBUG" in self.settings:
# print "lockfile(): Hardlink: Link failed."
@@ -305,9 +297,7 @@ class LockDir(object):
os.unlink(self.myhardlock)
if os.path.exists(self.lockfile):
os.unlink(self.lockfile)
- except SystemExit:
- raise
- except:
+ except Exception:
writemsg("Something strange happened to our hardlink locks.\n")
def add_hardlock_file_to_cleanup(self):
@@ -335,9 +325,7 @@ class LockDir(object):
try:
myhls = os.stat(link)
mylfs = os.stat(lock)
- except SystemExit:
- raise
- except:
+ except Exception:
myhls = None
mylfs = None
@@ -406,8 +394,6 @@ class LockDir(object):
# We're sweeping through, unlinking everyone's locks.
os.unlink(filename)
results.append("Unlinked: " + filename)
- except SystemExit:
- raise
except Exception:
pass
try:
@@ -415,16 +401,12 @@ class LockDir(object):
results.append("Unlinked: " + x)
os.unlink(mylockname)
results.append("Unlinked: " + mylockname)
- except SystemExit:
- raise
except Exception:
pass
else:
try:
os.unlink(mylockname)
results.append("Unlinked: " + mylockname)
- except SystemExit:
- raise
except Exception:
pass
return results
diff --git a/catalyst/main.py b/catalyst/main.py
index 04f689e..4e83414 100644
--- a/catalyst/main.py
+++ b/catalyst/main.py
@@ -95,7 +95,7 @@ def parse_config(myconfig):
myconfig = catalyst.config.ConfigParser(config_file)
myconf.update(myconfig.get_values())
- except:
+ except Exception:
print "!!! catalyst: Unable to parse configuration file, "+myconfig
sys.exit(1)
diff --git a/catalyst/support.py b/catalyst/support.py
index 90c59eb..f184ed7 100644
--- a/catalyst/support.py
+++ b/catalyst/support.py
@@ -22,9 +22,7 @@ DESIRED_RLIMIT = 0
try:
import resource
max_fd_limit=resource.getrlimit(resource.RLIMIT_NOFILE)[DESIRED_RLIMIT]
-except SystemExit, e:
- raise
-except:
+except Exception:
# hokay, no resource module.
max_fd_limit=256
@@ -48,7 +46,7 @@ def read_from_clst(path):
myline = ''
try:
myf = open(path, "r")
- except:
+ except Exception:
return -1
#raise CatalystError("Could not open file " + path)
for line in myf.readlines():
@@ -136,10 +134,7 @@ def cmd(mycmd, myexc="", env=None, debug=False, fail_func=None):
if debug:
print "***** cmd(); args =", args
- try:
- proc = Popen(args, env=env)
- except:
- raise
+ proc = Popen(args, env=env)
if proc.wait() != 0:
if fail_func:
print "CMD(), NON-Zero command return. Running fail_func()"
@@ -243,7 +238,7 @@ def read_makeconf(mymakeconffile):
try:
import portage.util
return portage.util.getconfig(mymakeconffile, tolerant=1, allow_sourcing=True)
- except:
+ except Exception:
try:
import portage_util
return portage_util.getconfig(mymakeconffile, tolerant=1, allow_sourcing=True)
@@ -252,7 +247,7 @@ def read_makeconf(mymakeconffile):
mylines=myf.readlines()
myf.close()
return parse_makeconf(mylines)
- except:
+ except Exception:
raise CatalystError("Could not parse make.conf file " +
mymakeconffile, print_traceback=True)
else:
diff --git a/targets/stage1/build.py b/targets/stage1/build.py
index be1bc4d..fa4fd13 100755
--- a/targets/stage1/build.py
+++ b/targets/stage1/build.py
@@ -33,7 +33,7 @@ for idx in range(0, len(pkgs)):
buildpkgs[bidx] = pkgs[idx]
if buildpkgs[bidx][0:1] == "*":
buildpkgs[bidx] = buildpkgs[bidx][1:]
- except:
+ except Exception:
pass
for b in buildpkgs:
--
2.5.2
next prev parent reply other threads:[~2015-10-06 15:05 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-06 15:05 [gentoo-catalyst] [PATCH 01/13] lint: fix duplicate fcntl import Mike Frysinger
2015-10-06 15:05 ` [gentoo-catalyst] [PATCH 02/13] lint: unwrap multiple statements Mike Frysinger
2015-10-06 15:05 ` [gentoo-catalyst] [PATCH 03/13] lint: fix bad indentation Mike Frysinger
2015-10-06 15:05 ` [gentoo-catalyst] [PATCH 04/13] lint: convert funcs to @staticmethod where it makes sense Mike Frysinger
2015-10-06 15:05 ` Mike Frysinger [this message]
2015-10-06 15:05 ` [gentoo-catalyst] [PATCH 06/13] lint: avoid relative imports Mike Frysinger
2015-10-06 15:05 ` [gentoo-catalyst] [PATCH 07/13] fileops: fix passing of gid/uid/minimal args Mike Frysinger
2015-10-06 15:05 ` [gentoo-catalyst] [PATCH 08/13] lint: revise wildcard import Mike Frysinger
2015-10-06 15:05 ` [gentoo-catalyst] [PATCH 09/13] lint: mark unused func args Mike Frysinger
2015-10-06 15:05 ` [gentoo-catalyst] [PATCH 10/13] lint: init all members in __init__ Mike Frysinger
2015-10-06 15:05 ` [gentoo-catalyst] [PATCH 11/13] version: use the passed in value Mike Frysinger
2015-10-06 15:05 ` [gentoo-catalyst] [PATCH 12/13] targets: fix bad set_build_kernel_vars call Mike Frysinger
2015-10-06 15:05 ` [gentoo-catalyst] [PATCH 13/13] lint: clean up superfluous parens Mike Frysinger
2015-10-06 15:27 ` Brian Dolbec
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1444143929-26705-5-git-send-email-vapier@gentoo.org \
--to=vapier@gentoo.org \
--cc=gentoo-catalyst@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox