Adjust pre-upload to give cleaner errors.
_report_error will now throw a specific exception. Error handlers
will check for that exception and give friendler errors than a
stack trace.
BUG=None
TEST=Used it.
Change-Id: If686d3a48ca6605e7ae501a9ed81df387650b6ae
Reviewed-on: http://gerrit.chromium.org/gerrit/379
Reviewed-by: Ryan Cui <rcui@chromium.org>
Tested-by: Don Garrett <dgarrett@chromium.org>
diff --git a/pre-upload.py b/pre-upload.py
index a60e68c..eb95d70 100644
--- a/pre-upload.py
+++ b/pre-upload.py
@@ -8,6 +8,8 @@
import sys
import subprocess
+class VerifyException(Exception):
+ pass
# General Helpers
@@ -94,7 +96,7 @@
"""
if items:
msg += '\n' + '\n'.join(items)
- raise Exception(msg)
+ raise VerifyException(msg)
# Git Helpers
@@ -330,19 +332,27 @@
try:
commit_list = _get_commits()
- except:
+ except VerifyException as e:
print >> sys.stderr, "ERROR: project *%s*" % project
+ print >> sys.stderr, e
raise
for commit in commit_list:
try:
for hook in COMMON_HOOKS + project_specific_hooks:
hook(project, commit)
- except:
+ except VerifyException as e:
msg = 'ERROR: pre-upload failed: commit=%s, project=%s' % (commit[:8],
project)
+
print >> sys.stderr, msg
+ print >> sys.stderr
+ print >> sys.stderr, _get_commit_desc(commit)
+ print >> sys.stderr
+ print >> sys.stderr, e
+
raise
+
os.chdir(pwd)
@@ -350,8 +360,12 @@
def main(project_list, **kwargs):
hooks = _setup_project_hooks()
- for project in project_list:
- _run_project_hooks(project, hooks)
+
+ try:
+ for project in project_list:
+ _run_project_hooks(project, hooks)
+ except VerifyException as e:
+ sys.exit(1)
if __name__ == '__main__':
main()