pre-upload: bubble up internal errors instead of exiting
Currently we exit if we hit an internal error (like invalid config file)
in a specific project repo. Lets return the error to the caller so it
can continue running across all repos, and so it can summarize the run
in general with a standard error message. Otherwise we don't currently
include a whole lot of info in the output which is confusing.
Bug: 124462370
Test: running `repo upload` across multiple repos doesn't exit immediately
Change-Id: I36022286750958f49a761d547b341447c520b411
diff --git a/pre-upload.py b/pre-upload.py
index fffc03c..ac976e7 100755
--- a/pre-upload.py
+++ b/pre-upload.py
@@ -179,7 +179,7 @@
global_paths=global_paths)
except rh.config.ValidationError as e:
print('invalid config file: %s' % (e,), file=sys.stderr)
- sys.exit(1)
+ return None
return config
@@ -236,13 +236,13 @@
if len(proj_dirs) == 0:
print('%s cannot be found.' % project_name, file=sys.stderr)
print('Please specify a valid project.', file=sys.stderr)
- return 0
+ return False
if len(proj_dirs) > 1:
print('%s is associated with multiple directories.' % project_name,
file=sys.stderr)
print('Please specify a directory to help disambiguate.',
file=sys.stderr)
- return 0
+ return False
proj_dir = proj_dirs[0]
pwd = os.getcwd()
@@ -251,6 +251,8 @@
# If the repo has no pre-upload hooks enabled, then just return.
config = _get_project_config()
+ if not config:
+ return False
hooks = list(config.callable_hooks())
if not hooks:
return True
@@ -262,7 +264,7 @@
except rh.utils.RunCommandError as e:
print('upstream remote cannot be found: %s' % (e,), file=sys.stderr)
print('Did you run repo start?', file=sys.stderr)
- sys.exit(1)
+ return False
os.environ.update({
'REPO_LREV': rh.git.get_commit_for_ref(upstream_branch),
'REPO_PATH': proj_dir,