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

--HG--
extra : rebase_source : a821159bd12a449ed1a0edf21a1f9eb29711ad95
This commit is contained in:
Gregory Szorc 2017-08-24 17:09:09 -07:00
Родитель e04ee6faf7
Коммит 276defc2a7
2 изменённых файлов: 10 добавлений и 9 удалений

Просмотреть файл

@ -169,11 +169,8 @@ def bootstrap(topsrcdir, mozilla_dir=None):
# 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):

Просмотреть файл

@ -14,6 +14,10 @@ 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):
@ -30,11 +34,11 @@ def get_tool_path(tool):
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):