diff options
author | Conley Owens <cco3@android.com> | 2012-11-14 14:18:06 -0800 |
---|---|---|
committer | Conley Owens <cco3@android.com> | 2012-11-14 14:18:06 -0800 |
commit | 7ba25bedf97643528ecef049cabe0b9d1c589131 (patch) | |
tree | b49cc04a8d030c784e7f46f6338c1c7f5c5977ac /main.py | |
parent | 98ffba1401056e2d88d3f3898b6fbf5d7d3931a4 (diff) | |
download | git-repo-7ba25bedf97643528ecef049cabe0b9d1c589131.tar.gz |
Simplify error handling in subcommand execution
Instead of using a nested try (which repo is plagued with), use a single
try when executing the appropriate subcommand.
Change-Id: I32dbfc010c740c0cc42ef8fb6a83dfe87f87e54a
Diffstat (limited to 'main.py')
-rwxr-xr-x | main.py | 31 |
1 files changed, 15 insertions, 16 deletions
@@ -131,32 +131,31 @@ class _Repo(object): | |||
131 | if use_pager: | 131 | if use_pager: |
132 | RunPager(config) | 132 | RunPager(config) |
133 | 133 | ||
134 | start = time.time() | ||
134 | try: | 135 | try: |
135 | start = time.time() | 136 | result = cmd.Execute(copts, cargs) |
136 | try: | ||
137 | result = cmd.Execute(copts, cargs) | ||
138 | finally: | ||
139 | elapsed = time.time() - start | ||
140 | hours, remainder = divmod(elapsed, 3600) | ||
141 | minutes, seconds = divmod(remainder, 60) | ||
142 | if gopts.time: | ||
143 | if hours == 0: | ||
144 | print('real\t%dm%.3fs' % (minutes, seconds), file=sys.stderr) | ||
145 | else: | ||
146 | print('real\t%dh%dm%.3fs' % (hours, minutes, seconds), | ||
147 | file=sys.stderr) | ||
148 | except DownloadError as e: | 137 | except DownloadError as e: |
149 | print('error: %s' % str(e), file=sys.stderr) | 138 | print('error: %s' % str(e), file=sys.stderr) |
150 | return 1 | 139 | result = 1 |
151 | except ManifestInvalidRevisionError as e: | 140 | except ManifestInvalidRevisionError as e: |
152 | print('error: %s' % str(e), file=sys.stderr) | 141 | print('error: %s' % str(e), file=sys.stderr) |
153 | return 1 | 142 | result = 1 |
154 | except NoSuchProjectError as e: | 143 | except NoSuchProjectError as e: |
155 | if e.name: | 144 | if e.name: |
156 | print('error: project %s not found' % e.name, file=sys.stderr) | 145 | print('error: project %s not found' % e.name, file=sys.stderr) |
157 | else: | 146 | else: |
158 | print('error: no project in current directory', file=sys.stderr) | 147 | print('error: no project in current directory', file=sys.stderr) |
159 | return 1 | 148 | result = 1 |
149 | finally: | ||
150 | elapsed = time.time() - start | ||
151 | hours, remainder = divmod(elapsed, 3600) | ||
152 | minutes, seconds = divmod(remainder, 60) | ||
153 | if gopts.time: | ||
154 | if hours == 0: | ||
155 | print('real\t%dm%.3fs' % (minutes, seconds), file=sys.stderr) | ||
156 | else: | ||
157 | print('real\t%dh%dm%.3fs' % (hours, minutes, seconds), | ||
158 | file=sys.stderr) | ||
160 | 159 | ||
161 | return result | 160 | return result |
162 | 161 | ||