Merge "Simplify error handling in subcommand execution"

This commit is contained in:
Conley Owens 2012-11-14 16:22:41 -08:00 committed by Gerrit Code Review
commit e66291f6d0

25
main.py
View File

@ -131,10 +131,21 @@ class _Repo(object):
if use_pager: if use_pager:
RunPager(config) RunPager(config)
try:
start = time.time() start = time.time()
try: try:
result = cmd.Execute(copts, cargs) 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 NoSuchProjectError as e:
if e.name:
print('error: project %s not found' % e.name, file=sys.stderr)
else:
print('error: no project in current directory', file=sys.stderr)
result = 1
finally: finally:
elapsed = time.time() - start elapsed = time.time() - start
hours, remainder = divmod(elapsed, 3600) hours, remainder = divmod(elapsed, 3600)
@ -145,18 +156,6 @@ class _Repo(object):
else: else:
print('real\t%dh%dm%.3fs' % (hours, minutes, seconds), print('real\t%dh%dm%.3fs' % (hours, minutes, seconds),
file=sys.stderr) file=sys.stderr)
except DownloadError as e:
print('error: %s' % str(e), file=sys.stderr)
return 1
except ManifestInvalidRevisionError as e:
print('error: %s' % str(e), file=sys.stderr)
return 1
except NoSuchProjectError as e:
if e.name:
print('error: project %s not found' % e.name, file=sys.stderr)
else:
print('error: no project in current directory', file=sys.stderr)
return 1
return result return result