autoland: fix error handling in run_hg (bug 1368516) r?smacleod draft
authorbyron jones <glob@mozilla.com>
Tue, 01 Aug 2017 21:58:40 +0800
changeset 11686 c56e3c87507a40565d06c4078a2788fed57ce88d
parent 11685 32cdc7c6ce887ce2f68ab3c356ce002efffb52fd
child 11687 5ef83a3f1a74b9a89233ae3278bd3ec081d677a9
push id1790
push userbjones@mozilla.com
push dateTue, 19 Sep 2017 04:17:41 +0000
reviewerssmacleod
bugs1368516
autoland: fix error handling in run_hg (bug 1368516) r?smacleod In my travels I found a bug in the error handling of run_hg - out.getvalue() wasn't being called everywhere. Moved the getvalue() call to run_hg so the callers don't need to remember to do it. MozReview-Commit-ID: EvTBqBhgmm
autoland/autoland/transplant.py
--- a/autoland/autoland/transplant.py
+++ b/autoland/autoland/transplant.py
@@ -11,18 +11,17 @@ REPO_CONFIG = {}
 logger = logging.getLogger('autoland')
 
 
 class HgCommandError(Exception):
     def __init__(self, hg_args, out):
         # we want to strip out any sensitive --config options
         hg_args = map(lambda x: x if not x.startswith('bugzilla') else 'xxx',
                       hg_args)
-        message = 'hg error in cmd: hg %s: %s' % (' '.join(hg_args),
-                                                  out.getvalue())
+        message = 'hg error in cmd: hg %s: %s' % (' '.join(hg_args), out)
         super(self.__class__, self).__init__(message)
 
 
 class Transplant(object):
     """Transplant a specified revision and ancestors to the specified tree."""
 
     def __init__(self, tree, destination, rev):
         # These values can appear in command arguments. Don't let unicode leak
@@ -112,19 +111,22 @@ class Transplant(object):
         self.validate_descriptions(commit_descriptions)
         return base_revision
 
     def run_hg(self, args):
         logger.info('rev: %s: executing: %s' % (self.source_rev, args))
         out = hglib.util.BytesIO()
         out_channels = {b'o': out.write, b'e': out.write}
         ret = self.hg_repo.runcommand(args, {}, out_channels)
+        out = out.getvalue()
         if ret:
-            raise hglib.error.CommandError(args, ret, out, None)
-        return out.getvalue()
+            if out:
+                logging.error(out.rstrip())
+            raise hglib.error.CommandError(args, ret, out, '')
+        return out
 
     def run_hg_cmds(self, cmds):
         last_result = ''
         for cmd in cmds:
             try:
                 last_result = self.run_hg(cmd)
             except hglib.error.CommandError as e:
                 raise HgCommandError(cmd, e.out)
@@ -156,17 +158,17 @@ class Transplant(object):
                 ['update', '--clean', '-r', remote_rev],
                 ['pull', self.tree, '-r', self.source_rev],
                 ['update', self.source_rev]]
 
         for cmd in cmds:
             try:
                 self.run_hg(cmd)
             except hglib.error.CommandError as e:
-                output = e.out.getvalue()
+                output = e.out
                 if 'no changes found' in output:
                     # we've already pulled this revision
                     continue
                 elif 'abort: no rebase in progress' in output:
                     # there was no rebase in progress, nothing to see here
                     continue
                 else:
                     raise HgCommandError(cmd, e.out)
@@ -208,17 +210,17 @@ class Transplant(object):
         # our content, as there is no content in the destination to conflict
         # with us.
         if remote_tip == '0' * 12:
             cmd.extend(['--tool', ':other'])
 
         try:
             self.run_hg(cmd)
         except hglib.error.CommandError as e:
-            if 'nothing to rebase' not in e.out.getvalue():
+            if 'nothing to rebase' not in e.out:
                 raise HgCommandError(cmd, e.out)
 
         return self.run_hg_cmds([
             ['log', '-r', 'tip', '-T', '{node|short}']
         ])
 
     def validate_descriptions(self, commit_descriptions):
         # Match outgoing commit descriptions against incoming commit