Bug 1393503 - Proper error handling for failure to find VCS tool; r?glandium
``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
--- 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)