mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
[git_trace2] Add logs for critical cmds
Trace logs emitted from repo are not useful on error for many critical commands. This change adds errors for critical commands to trace logs. Change-Id: Ideb9358bee31e540bd84a94327a09ff9b0246a77 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/373814 Reviewed-by: Joanna Wang <jojwang@google.com> Tested-by: Josip Sokcevic <sokcevic@google.com> Commit-Queue: Josip Sokcevic <sokcevic@google.com> Reviewed-by: Gavin Mak <gavinmak@google.com>
This commit is contained in:
parent
2ad5d50874
commit
131fc96381
@ -198,9 +198,11 @@ class EventLog(object):
|
|||||||
event["value"] = value
|
event["value"] = value
|
||||||
self._log.append(event)
|
self._log.append(event)
|
||||||
|
|
||||||
def ErrorEvent(self, msg, fmt):
|
def ErrorEvent(self, msg, fmt=None):
|
||||||
"""Append a 'error' event to the current log."""
|
"""Append a 'error' event to the current log."""
|
||||||
error_event = self._CreateEventDict("error")
|
error_event = self._CreateEventDict("error")
|
||||||
|
if fmt is None:
|
||||||
|
fmt = msg
|
||||||
error_event["msg"] = msg
|
error_event["msg"] = msg
|
||||||
error_event["fmt"] = fmt
|
error_event["fmt"] = fmt
|
||||||
self._log.append(error_event)
|
self._log.append(error_event)
|
||||||
|
@ -341,10 +341,12 @@ to update the working directory files.
|
|||||||
quiet=opt.quiet,
|
quiet=opt.quiet,
|
||||||
)
|
)
|
||||||
except wrapper.CloneFailure:
|
except wrapper.CloneFailure:
|
||||||
|
err_msg = "fatal: double check your --repo-rev setting."
|
||||||
print(
|
print(
|
||||||
"fatal: double check your --repo-rev setting.",
|
err_msg,
|
||||||
file=sys.stderr,
|
file=sys.stderr,
|
||||||
)
|
)
|
||||||
|
self.git_event_log.ErrorEvent(err_msg)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
branch = rp.GetBranch("default")
|
branch = rp.GetBranch("default")
|
||||||
branch.merge = remote_ref
|
branch.merge = remote_ref
|
||||||
|
@ -206,7 +206,9 @@ branch but need to incorporate new upstream changes "underneath" them.
|
|||||||
ret += 1
|
ret += 1
|
||||||
|
|
||||||
if ret:
|
if ret:
|
||||||
out.fail("%i projects had errors", ret)
|
msg_fmt = "%d projects had errors"
|
||||||
|
self.git_event_log.ErrorEvent(msg_fmt % (ret), msg_fmt)
|
||||||
|
out.fail(msg_fmt, ret)
|
||||||
out.nl()
|
out.nl()
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
@ -168,4 +168,6 @@ revision specified in the manifest.
|
|||||||
% (p.RelPath(local=opt.this_manifest_only), nb),
|
% (p.RelPath(local=opt.this_manifest_only), nb),
|
||||||
file=sys.stderr,
|
file=sys.stderr,
|
||||||
)
|
)
|
||||||
|
msg_fmt = "cannot start %d project(s)"
|
||||||
|
self.git_event_log.ErrorEvent(msg_fmt % (len(err)), msg_fmt)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -1695,32 +1695,29 @@ later is required to fix a server side protocol bug.
|
|||||||
|
|
||||||
# If we saw an error, exit with code 1 so that other scripts can check.
|
# If we saw an error, exit with code 1 so that other scripts can check.
|
||||||
if err_event.is_set():
|
if err_event.is_set():
|
||||||
print("\nerror: Unable to fully sync the tree.", file=sys.stderr)
|
# Add a new line so it's easier to read.
|
||||||
|
print("\n", file=sys.stderr)
|
||||||
|
|
||||||
|
def print_and_log(err_msg):
|
||||||
|
self.git_event_log.ErrorEvent(err_msg)
|
||||||
|
print(err_msg, file=sys.stderr)
|
||||||
|
|
||||||
|
print_and_log("error: Unable to fully sync the tree")
|
||||||
if err_network_sync:
|
if err_network_sync:
|
||||||
print(
|
print_and_log("error: Downloading network changes failed.")
|
||||||
"error: Downloading network changes failed.",
|
|
||||||
file=sys.stderr,
|
|
||||||
)
|
|
||||||
if err_update_projects:
|
if err_update_projects:
|
||||||
print(
|
print_and_log("error: Updating local project lists failed.")
|
||||||
"error: Updating local project lists failed.",
|
|
||||||
file=sys.stderr,
|
|
||||||
)
|
|
||||||
if err_update_linkfiles:
|
if err_update_linkfiles:
|
||||||
print(
|
print_and_log("error: Updating copyfiles or linkfiles failed.")
|
||||||
"error: Updating copyfiles or linkfiles failed.",
|
|
||||||
file=sys.stderr,
|
|
||||||
)
|
|
||||||
if err_checkout:
|
if err_checkout:
|
||||||
print(
|
print_and_log("error: Checking out local projects failed.")
|
||||||
"error: Checking out local projects failed.",
|
|
||||||
file=sys.stderr,
|
|
||||||
)
|
|
||||||
if err_results:
|
if err_results:
|
||||||
|
# Don't log repositories, as it may contain sensitive info.
|
||||||
print(
|
print(
|
||||||
"Failing repos:\n%s" % "\n".join(err_results),
|
"Failing repos:\n%s" % "\n".join(err_results),
|
||||||
file=sys.stderr,
|
file=sys.stderr,
|
||||||
)
|
)
|
||||||
|
# Not useful to log.
|
||||||
print(
|
print(
|
||||||
'Try re-running with "-j1 --fail-fast" to exit at the first '
|
'Try re-running with "-j1 --fail-fast" to exit at the first '
|
||||||
"error.",
|
"error.",
|
||||||
|
@ -657,6 +657,7 @@ Gerrit Code Review: https://www.gerritcodereview.com/
|
|||||||
|
|
||||||
branch.uploaded = True
|
branch.uploaded = True
|
||||||
except UploadError as e:
|
except UploadError as e:
|
||||||
|
self.git_event_log.ErrorEvent("upload error: " + str(e))
|
||||||
branch.error = e
|
branch.error = e
|
||||||
branch.uploaded = False
|
branch.uploaded = False
|
||||||
have_errors = True
|
have_errors = True
|
||||||
|
Loading…
Reference in New Issue
Block a user