autoland: refactor: use exceptions to signal failure (
bug 1349997); r?gps
Instead of returning a tuple with (bool, result), return the result on success,
and throw an Exception on failures.
MozReview-Commit-ID: JvoVCAv7RT2
--- a/autoland/autoland/autoland.py
+++ b/autoland/autoland/autoland.py
@@ -114,20 +114,26 @@ def handle_pending_transplants(dbconn):
tree, rev, destination, attempts + 1))
# TODO: We should break the transplant call into two steps, one
# to pull down the commits to transplant, and another
# one to rebase it and attempt to push so we don't
# duplicate work unnecessarily if we have to rebase more
# than once.
os.environ['AUTOLAND_REQUEST_USER'] = requester
- landed, result = transplant.transplant(tree, destination, rev,
- trysyntax, push_bookmark,
- commit_descriptions)
- del os.environ['AUTOLAND_REQUEST_USER']
+ try:
+ result = transplant.transplant(tree, destination, rev,
+ trysyntax, push_bookmark,
+ commit_descriptions)
+ landed = True
+ except Exception as e:
+ result = str(e)
+ landed = False
+ finally:
+ del os.environ['AUTOLAND_REQUEST_USER']
logger.info('transplant from tree: %s rev: %s attempt: %s: %s' % (
tree, rev, attempts + 1, result))
if landed or 'abort: push creates new remote head' not in result:
break
attempts += 1
--- a/autoland/autoland/transplant.py
+++ b/autoland/autoland/transplant.py
@@ -31,34 +31,30 @@ def transplant(tree, destination, rev, t
# These values can appear in command arguments. Don't let unicode leak
# into these.
assert isinstance(tree, str)
assert isinstance(destination, str)
assert isinstance(rev, str)
if push_bookmark:
assert isinstance(push_bookmark, str)
- try:
- path = config.get('repos').get(tree,
- os.path.join(os.path.sep, 'repos', tree))
- configs = ['ui.interactive=False']
- with hglib.open(path, encoding='utf-8', configs=configs) as hg_repo:
- tp = Transplant(hg_repo, tree, destination, rev)
+ path = config.get('repos').get(tree,
+ os.path.join(os.path.sep, 'repos', tree))
+ configs = ['ui.interactive=False']
+ with hglib.open(path, encoding='utf-8', configs=configs) as hg_repo:
+ tp = Transplant(hg_repo, tree, destination, rev)
- if trysyntax:
- return True, tp.push_try(trysyntax)
+ if trysyntax:
+ return tp.push_try(trysyntax)
- elif push_bookmark:
- return True, tp.push_bookmark(commit_descriptions,
- push_bookmark)
+ elif push_bookmark:
+ return tp.push_bookmark(commit_descriptions, push_bookmark)
- else:
- return True, tp.push(commit_descriptions)
- except Exception as e:
- return False, str(e)
+ else:
+ return tp.push(commit_descriptions)
class Transplant:
def __init__(self, hg_repo, tree, destination, rev):
self.hg_repo = hg_repo
self.tree = tree
self.destination = destination
self.source_rev = rev