Bug 1393503 - Proper error handling for failure to find VCS tool; r=glandium,nalexander
authorGregory Szorc <gps@mozilla.com>
Thu, 24 Aug 2017 17:09:09 -0700
changeset 376989 8c56313471f8a4b5444ae90165e748f9ad66a534
parent 376988 8396a848ae256af62f3f67779d69c8434d378c23
child 376990 a5f01ec89dd2342f3d0478020b16aefd1dbed7ff
push id32397
push userphilringnalda@gmail.com
push dateSun, 27 Aug 2017 01:13:26 +0000
treeherdermozilla-central@30ee0dcda883 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium, nalexander
bugs1393503
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1393503 - Proper error handling for failure to find VCS tool; r=glandium,nalexander ``print()`` has no business being in library code like this. It was a holdover from this code being copied from bootstrap. So remove it. While we're here, replace the generic exception with a specific one. We don't want to be swallowing bugs via ``except Exception``. MozReview-Commit-ID: 49goUstfPBz
build/mach_bootstrap.py
python/mozversioncontrol/mozversioncontrol/__init__.py
--- a/build/mach_bootstrap.py
+++ b/build/mach_bootstrap.py
@@ -164,21 +164,18 @@ def bootstrap(topsrcdir, mozilla_dir=Non
     def resolve_repository():
         import mozversioncontrol
 
         try:
             # This API doesn't respect the vcs binary choices from configure.
             # If we ever need to use the VCS binary here, consider something
             # more robust.
             return mozversioncontrol.get_repository_object(path=mozilla_dir)
-        except mozversioncontrol.InvalidRepoPath:
-            return None
-        # This is mainly to catch failures resolving the VCS binary path.
-        # TODO Change mozversioncontrol to raise non-generic exception.
-        except Exception:
+        except (mozversioncontrol.InvalidRepoPath,
+                mozversioncontrol.MissingVCSTool):
             return None
 
     def telemetry_handler(context, data):
         # We have not opted-in to telemetry
         if 'BUILD_SYSTEM_TELEMETRY' not in os.environ:
             return
 
         telemetry_dir = os.path.join(get_state_dir()[0], 'telemetry')
--- a/python/mozversioncontrol/mozversioncontrol/__init__.py
+++ b/python/mozversioncontrol/mozversioncontrol/__init__.py
@@ -9,37 +9,41 @@ import errno
 import os
 import re
 import subprocess
 import which
 
 from distutils.version import LooseVersion
 
 
+class MissingVCSTool(Exception):
+    """Represents a failure to find a version control tool binary."""
+
+
 def get_tool_path(tool):
     """Obtain the path of `tool`."""
     if os.path.isabs(tool) and os.path.exists(tool):
         return tool
 
     # We use subprocess in places, which expects a Win32 executable or
     # batch script. On some versions of MozillaBuild, we have "hg.exe",
     # "hg.bat," and "hg" (a Python script). "which" will happily return the
     # Python script, which will cause subprocess to choke. Explicitly favor
     # the Windows version over the plain script.
     try:
         return which.which(tool + '.exe')
     except which.WhichError:
         try:
             return which.which(tool)
         except which.WhichError as e:
-            print(e)
+            pass
 
-    raise Exception('Unable to obtain %s path. Try running '
-                    '|mach bootstrap| to ensure your environment is up to '
-                    'date.' % tool)
+    raise MissingVCSTool('Unable to obtain %s path. Try running '
+                         '|mach bootstrap| to ensure your environment is up to '
+                         'date.' % tool)
 
 
 class Repository(object):
     __metaclass__ = abc.ABCMeta
 
     '''A class wrapping utility methods around version control repositories.'''
     def __init__(self, path, tool):
         self.path = os.path.abspath(path)