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
diff --git a/main.py b/main.py
index 3661776..72fb39b 100755
--- a/main.py
+++ b/main.py
@@ -129,8 +129,15 @@
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 @@
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: