diff options
| author | Jason Chang <jasonnc@google.com> | 2023-08-03 14:38:00 -0700 |
|---|---|---|
| committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-08-07 23:56:07 +0000 |
| commit | f9aacd4087b02948da9a7878da48ea186ab99d5a (patch) | |
| tree | b683190635cd6fcb7cf817837ad0c4259b53078f /fetch.py | |
| parent | b8a7b4a629c3435d77a3266a4e6dce51dc342bd9 (diff) | |
| download | git-repo-f9aacd4087b02948da9a7878da48ea186ab99d5a.tar.gz | |
Raise repo exit errors in place of sys.exit
Bug: b/293344017
Change-Id: I92d81c78eba8ff31b5252415f4c9a515a6c76411
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/381774
Tested-by: Jason Chang <jasonnc@google.com>
Reviewed-by: Joanna Wang <jojwang@google.com>
Commit-Queue: Jason Chang <jasonnc@google.com>
Diffstat (limited to 'fetch.py')
| -rw-r--r-- | fetch.py | 9 |
1 files changed, 8 insertions, 1 deletions
| @@ -18,6 +18,11 @@ import subprocess | |||
| 18 | import sys | 18 | import sys |
| 19 | from urllib.parse import urlparse | 19 | from urllib.parse import urlparse |
| 20 | from urllib.request import urlopen | 20 | from urllib.request import urlopen |
| 21 | from error import RepoExitError | ||
| 22 | |||
| 23 | |||
| 24 | class FetchFileError(RepoExitError): | ||
| 25 | """Exit error when fetch_file fails.""" | ||
| 21 | 26 | ||
| 22 | 27 | ||
| 23 | def fetch_file(url, verbose=False): | 28 | def fetch_file(url, verbose=False): |
| @@ -29,6 +34,7 @@ def fetch_file(url, verbose=False): | |||
| 29 | scheme = urlparse(url).scheme | 34 | scheme = urlparse(url).scheme |
| 30 | if scheme == "gs": | 35 | if scheme == "gs": |
| 31 | cmd = ["gsutil", "cat", url] | 36 | cmd = ["gsutil", "cat", url] |
| 37 | errors = [] | ||
| 32 | try: | 38 | try: |
| 33 | result = subprocess.run( | 39 | result = subprocess.run( |
| 34 | cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True | 40 | cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True |
| @@ -41,9 +47,10 @@ def fetch_file(url, verbose=False): | |||
| 41 | ) | 47 | ) |
| 42 | return result.stdout | 48 | return result.stdout |
| 43 | except subprocess.CalledProcessError as e: | 49 | except subprocess.CalledProcessError as e: |
| 50 | errors.append(e) | ||
| 44 | print( | 51 | print( |
| 45 | 'fatal: error running "gsutil": %s' % e.stderr, file=sys.stderr | 52 | 'fatal: error running "gsutil": %s' % e.stderr, file=sys.stderr |
| 46 | ) | 53 | ) |
| 47 | sys.exit(1) | 54 | raise FetchFileError(aggregate_errors=errors) |
| 48 | with urlopen(url) as f: | 55 | with urlopen(url) as f: |
| 49 | return f.read() | 56 | return f.read() |
