Skip to content

Commit 53e902a

Browse files
dsandlerdpursehouse
authored andcommitted
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
1 parent 093fdb6 commit 53e902a

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

error.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ class ManifestInvalidRevisionError(Exception):
2424
class NoManifestException(Exception):
2525
"""The required manifest does not exist.
2626
"""
27+
def __init__(self, path, reason):
28+
super(NoManifestException, self).__init__()
29+
self.path = path
30+
self.reason = reason
31+
32+
def __str__(self):
33+
return self.reason
2734

2835
class EditorError(Exception):
2936
"""Unspecified error from the user's text editor.

main.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,15 @@ def _Run(self, argv):
129129
file=sys.stderr)
130130
return 1
131131

132-
copts, cargs = cmd.OptionParser.parse_args(argv)
133-
copts = cmd.ReadEnvironmentOptions(copts)
132+
try:
133+
copts, cargs = cmd.OptionParser.parse_args(argv)
134+
copts = cmd.ReadEnvironmentOptions(copts)
135+
except NoManifestException as e:
136+
print('error: in `%s`: %s' % (' '.join([name] + argv), str(e)),
137+
file=sys.stderr)
138+
print('error: manifest missing or unreadable -- please run init',
139+
file=sys.stderr)
140+
return 1
134141

135142
if not gopts.no_pager and not isinstance(cmd, InteractiveCommand):
136143
config = cmd.manifest.globalConfig
@@ -146,15 +153,13 @@ def _Run(self, argv):
146153
start = time.time()
147154
try:
148155
result = cmd.Execute(copts, cargs)
149-
except DownloadError as e:
150-
print('error: %s' % str(e), file=sys.stderr)
151-
result = 1
152-
except ManifestInvalidRevisionError as e:
153-
print('error: %s' % str(e), file=sys.stderr)
154-
result = 1
155-
except NoManifestException as e:
156-
print('error: manifest required for this command -- please run init',
157-
file=sys.stderr)
156+
except (DownloadError, ManifestInvalidRevisionError,
157+
NoManifestException) as e:
158+
print('error: in `%s`: %s' % (' '.join([name] + argv), str(e)),
159+
file=sys.stderr)
160+
if isinstance(e, NoManifestException):
161+
print('error: manifest missing or unreadable -- please run init',
162+
file=sys.stderr)
158163
result = 1
159164
except NoSuchProjectError as e:
160165
if e.name:

project.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,8 +2327,8 @@ def GetHead(self):
23272327
path = os.path.join(self._project.worktree, '.git', HEAD)
23282328
try:
23292329
fd = open(path, 'rb')
2330-
except IOError:
2331-
raise NoManifestException(path)
2330+
except IOError as e:
2331+
raise NoManifestException(path, str(e))
23322332
try:
23332333
line = fd.read()
23342334
finally:

0 commit comments

Comments
 (0)