From f9aacd4087b02948da9a7878da48ea186ab99d5a Mon Sep 17 00:00:00 2001 From: Jason Chang Date: Thu, 3 Aug 2023 14:38:00 -0700 Subject: 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 Reviewed-by: Joanna Wang Commit-Queue: Jason Chang --- fetch.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'fetch.py') diff --git a/fetch.py b/fetch.py index 31f8152f..cf8d1d7d 100644 --- a/fetch.py +++ b/fetch.py @@ -18,6 +18,11 @@ import subprocess import sys from urllib.parse import urlparse from urllib.request import urlopen +from error import RepoExitError + + +class FetchFileError(RepoExitError): + """Exit error when fetch_file fails.""" def fetch_file(url, verbose=False): @@ -29,6 +34,7 @@ def fetch_file(url, verbose=False): scheme = urlparse(url).scheme if scheme == "gs": cmd = ["gsutil", "cat", url] + errors = [] try: result = subprocess.run( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True @@ -41,9 +47,10 @@ def fetch_file(url, verbose=False): ) return result.stdout except subprocess.CalledProcessError as e: + errors.append(e) print( 'fatal: error running "gsutil": %s' % e.stderr, file=sys.stderr ) - sys.exit(1) + raise FetchFileError(aggregate_errors=errors) with urlopen(url) as f: return f.read() -- cgit v1.2.3-54-g00ecf