summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Sandler <dsandler@android.com>2014-03-09 13:20:02 -0400
committerDavid Pursehouse <david.pursehouse@sonymobile.com>2014-03-11 05:33:43 +0000
commit53e902a19b0b80e07ac55966d13c5c84c5b0e8ce (patch)
treee804b3826be8d5bb6153f2f9f4e482191e8b8642
parent093fdb6587bba081c4d34eb9ea500149b1090280 (diff)
More verbose errors for NoManifestExceptions.
The old "manifest required for this command -- please run init" is replaced by a more helpful message that lists the command repo was trying to execute (with arguments) as well as the str() of the NoManifestException. For example: > error: in `sync`: [Errno 2] No such file or directory: > 'path/to/.repo/manifests/.git/HEAD' > error: manifest missing or unreadable -- please run init Other failure points in basic command parsing and dispatch are more clearly explained in the same fashion. Change-Id: I6212e5c648bc5d57e27145d55a5391ca565e4149
-rw-r--r--error.py7
-rwxr-xr-xmain.py27
-rw-r--r--project.py4
3 files changed, 25 insertions, 13 deletions
diff --git a/error.py b/error.py
index 7e52b01..ff948f9 100644
--- a/error.py
+++ b/error.py
@@ -24,6 +24,13 @@ class ManifestInvalidRevisionError(Exception):
class NoManifestException(Exception):
"""The required manifest does not exist.
"""
+ def __init__(self, path, reason):
+ super(NoManifestException, self).__init__()
+ self.path = path
+ self.reason = reason
+
+ def __str__(self):
+ return self.reason
class EditorError(Exception):
"""Unspecified error from the user's text editor.
diff --git a/main.py b/main.py
index 3661776..72fb39b 100755
--- a/main.py
+++ b/main.py
@@ -129,8 +129,15 @@ class _Repo(object):
file=sys.stderr)
return 1
- copts, cargs = cmd.OptionParser.parse_args(argv)
- copts = cmd.ReadEnvironmentOptions(copts)
+ try:
+ copts, cargs = cmd.OptionParser.parse_args(argv)
+ copts = cmd.ReadEnvironmentOptions(copts)
+ except NoManifestException as e:
+ print('error: in `%s`: %s' % (' '.join([name] + argv), str(e)),
+ file=sys.stderr)
+ print('error: manifest missing or unreadable -- please run init',
+ file=sys.stderr)
+ return 1
if not gopts.no_pager and not isinstance(cmd, InteractiveCommand):
config = cmd.manifest.globalConfig
@@ -146,15 +153,13 @@ class _Repo(object):
start = time.time()
try:
result = cmd.Execute(copts, cargs)
- except DownloadError as e:
- print('error: %s' % str(e), file=sys.stderr)
- result = 1
- except ManifestInvalidRevisionError as e:
- print('error: %s' % str(e), file=sys.stderr)
- result = 1
- except NoManifestException as e:
- print('error: manifest required for this command -- please run init',
- file=sys.stderr)
+ except (DownloadError, ManifestInvalidRevisionError,
+ NoManifestException) as e:
+ print('error: in `%s`: %s' % (' '.join([name] + argv), str(e)),
+ file=sys.stderr)
+ if isinstance(e, NoManifestException):
+ print('error: manifest missing or unreadable -- please run init',
+ file=sys.stderr)
result = 1
except NoSuchProjectError as e:
if e.name:
diff --git a/project.py b/project.py
index d07b521..023cf73 100644
--- a/project.py
+++ b/project.py
@@ -2327,8 +2327,8 @@ class Project(object):
path = os.path.join(self._project.worktree, '.git', HEAD)
try:
fd = open(path, 'rb')
- except IOError:
- raise NoManifestException(path)
+ except IOError as e:
+ raise NoManifestException(path, str(e))
try:
line = fd.read()
finally: