upload: fix error handling

There was a bug in error handeling code that caused an uncaught
exception to be raised.

Bug: b/296316540
Change-Id: I49c72f29c00f26ba60de552f958bc6eddf841162
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/383254
Reviewed-by: Mike Frysinger <vapier@google.com>
Commit-Queue: Jason Chang <jasonnc@google.com>
Tested-by: Jason Chang <jasonnc@google.com>
This commit is contained in:
Jason Chang
2023-08-17 11:36:41 -07:00
committed by LUCI
parent 11cb96030e
commit 5a3a5f7cec
3 changed files with 204 additions and 133 deletions

View File

@ -1116,7 +1116,8 @@ class Project(object):
if not re.match(r"^.+[+-][0-9]+$", label):
raise UploadError(
f'invalid label syntax "{label}": labels use forms like '
"CodeReview+1 or Verified-1"
"CodeReview+1 or Verified-1",
project=self.name,
)
if dest_branch is None:
@ -1132,7 +1133,7 @@ class Project(object):
url = branch.remote.ReviewUrl(self.UserEmail, validate_certs)
if url is None:
raise UploadError("review not configured")
raise UploadError("review not configured", project=self.name)
cmd = ["push"]
if dryrun:
cmd.append("-n")
@ -1177,8 +1178,9 @@ class Project(object):
ref_spec = ref_spec + "%" + ",".join(opts)
cmd.append(ref_spec)
if GitCommand(self, cmd, bare=True).Wait() != 0:
raise UploadError("Upload failed")
GitCommand(
self, cmd, bare=True, capture_stderr=True, verify_command=True
).Wait()
if not dryrun:
msg = "posted to %s for %s" % (branch.remote.review, dest_branch)