From 6375554363c111fda70b7540c3c56a0e9cf1497b Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 16 Apr 2013 15:57:58 +0100 Subject: Stop using bare except: statements It is almost never a good idea to catch all exceptions, and then do nothing about them. This patch logs all caught exceptions so that the user has some possibilty to debug what is happening. Also, make ./check check for bare excepts and fail the test suite if it finds anything. --- morphlib/plugins/branch_and_merge_plugin.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'morphlib/plugins/branch_and_merge_plugin.py') diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py index 25f786e0..e39141cc 100644 --- a/morphlib/plugins/branch_and_merge_plugin.py +++ b/morphlib/plugins/branch_and_merge_plugin.py @@ -231,7 +231,9 @@ class BranchAndMergePlugin(cliapp.Plugin): try: return self.app.runcmd(['git', 'rev-parse', '--verify', ref], cwd=repodir)[0:40] - except: + except cliapp.AppException, e: + logging.info( + 'Ignoring error executing git rev-parse: %s' % str(e)) return None def resolve_reponame(self, reponame): @@ -558,11 +560,7 @@ class BranchAndMergePlugin(cliapp.Plugin): 'directory as a workspace: %s' % dirname) else: - try: - os.makedirs(dirname) - except: - raise cliapp.AppException('failed to create workspace: %s' % - dirname) + os.makedirs(dirname) os.mkdir(os.path.join(dirname, '.morph')) self.app.status(msg='Initialized morph workspace', chatty=True) @@ -600,7 +598,9 @@ class BranchAndMergePlugin(cliapp.Plugin): original_ref], cwd=repo_dir) return branch_dir - except: + except BaseException, e: + logging.error('Caught exception: %s' % str(e)) + logging.info('Removing half-finished branch %s' % branch_name) self.remove_branch_dir_safe(workspace, branch_name) raise @@ -1513,7 +1513,9 @@ class BranchAndMergePlugin(cliapp.Plugin): "case, and then repeat the 'morph merge' operation." % from_branch) self.app.status(msg="Merge successful") - except: + except BaseException, e: + logging.error('Caught exception: %s' % str(e)) + logging.info('Resetting half-finished merge') for repo_dir, sha1 in merged_repos.itervalues(): self.reset_work_tree_safe(repo_dir) raise -- cgit v1.2.1