aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-12-15 16:14:49 -0500
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-12-15 16:14:49 -0500
commit40386e66ce0effbb0d35127b222961c19dee12a1 (patch)
treeea4dac01f5f2f075f43adb63ff98fff2a1e7903b
parent0201055edbf2c061179d639ad7c47381bd3599ad (diff)
downloadb4-40386e66ce0effbb0d35127b222961c19dee12a1.tar.gz
Raise RuntimeError instead of exiting
It's a bad habit to exit anywhere other than from main() anyway. I should fix all cases of that in order to be both more pythonic and library-friendly. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r--b4/pr.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/b4/pr.py b/b4/pr.py
index e31afc1..095d782 100644
--- a/b4/pr.py
+++ b/b4/pr.py
@@ -242,7 +242,7 @@ def thanks_record_pr(lmsg):
def explode(gitdir, lmsg, mailfrom=None, retrieve_links=True, fpopts=None):
ecode = fetch_remote(gitdir, lmsg, check_sig=False, ty_track=False)
if ecode > 0:
- sys.exit(ecode)
+ raise RuntimeError('Fetching unsuccessful')
if not lmsg.pr_base_commit:
# Use git merge-base between HEAD and FETCH_HEAD to find
@@ -253,7 +253,7 @@ def explode(gitdir, lmsg, mailfrom=None, retrieve_links=True, fpopts=None):
if ecode > 0:
logger.critical('Could not find common ancestry.')
logger.critical(out)
- sys.exit(ecode)
+ raise RuntimeError('Could not find common ancestry')
lmsg.pr_base_commit = out.strip()
logger.info('Generating patches starting from the base-commit')
@@ -292,7 +292,7 @@ def explode(gitdir, lmsg, mailfrom=None, retrieve_links=True, fpopts=None):
with b4.git_format_patches(gitdir, lmsg.pr_base_commit, 'FETCH_HEAD', prefixes=prefixes, extraopts=fpopts) as pdir:
if pdir is None:
- sys.exit(1)
+ raise RuntimeError('Could not run format-patches')
for msgfile in sorted(os.listdir(pdir)):
with open(os.path.join(pdir, msgfile), 'rb') as fh:
@@ -458,7 +458,11 @@ def main(cmdargs):
# Set up a temporary clone
with b4.git_temp_clone(gitdir) as tc:
- msgs = explode(tc, lmsg, mailfrom=cmdargs.mailfrom, retrieve_links=cmdargs.getlinks)
+ try:
+ msgs = explode(tc, lmsg, mailfrom=cmdargs.mailfrom, retrieve_links=cmdargs.getlinks)
+ except RuntimeError:
+ sys.exit(1)
+
if msgs:
smbx = mailbox.mbox(savefile)
for msg in msgs: