summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosip Sokcevic <sokcevic@google.com>2023-05-12 17:00:46 -0700
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-05-17 18:06:14 +0000
commit131fc96381e112b0aa7a1012243e2ed5cfd3ec01 (patch)
treeb5c87a061a4bec40ba5cdf57ded2154aac763cfc
parent2ad5d508740a0bf3a4fe13bd27525b57da683a68 (diff)
downloadgit-repo-131fc96381e112b0aa7a1012243e2ed5cfd3ec01.tar.gz
[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>
-rw-r--r--git_trace2_event_log.py4
-rw-r--r--subcmds/init.py4
-rw-r--r--subcmds/rebase.py4
-rw-r--r--subcmds/start.py2
-rw-r--r--subcmds/sync.py31
-rw-r--r--subcmds/upload.py1
6 files changed, 26 insertions, 20 deletions
diff --git a/git_trace2_event_log.py b/git_trace2_event_log.py
index 820cbac0..46bd5e4b 100644
--- a/git_trace2_event_log.py
+++ b/git_trace2_event_log.py
@@ -198,9 +198,11 @@ class EventLog(object):
198 event["value"] = value 198 event["value"] = value
199 self._log.append(event) 199 self._log.append(event)
200 200
201 def ErrorEvent(self, msg, fmt): 201 def ErrorEvent(self, msg, fmt=None):
202 """Append a 'error' event to the current log.""" 202 """Append a 'error' event to the current log."""
203 error_event = self._CreateEventDict("error") 203 error_event = self._CreateEventDict("error")
204 if fmt is None:
205 fmt = msg
204 error_event["msg"] = msg 206 error_event["msg"] = msg
205 error_event["fmt"] = fmt 207 error_event["fmt"] = fmt
206 self._log.append(error_event) 208 self._log.append(error_event)
diff --git a/subcmds/init.py b/subcmds/init.py
index b5c2e3b5..9946466d 100644
--- a/subcmds/init.py
+++ b/subcmds/init.py
@@ -341,10 +341,12 @@ to update the working directory files.
341 quiet=opt.quiet, 341 quiet=opt.quiet,
342 ) 342 )
343 except wrapper.CloneFailure: 343 except wrapper.CloneFailure:
344 err_msg = "fatal: double check your --repo-rev setting."
344 print( 345 print(
345 "fatal: double check your --repo-rev setting.", 346 err_msg,
346 file=sys.stderr, 347 file=sys.stderr,
347 ) 348 )
349 self.git_event_log.ErrorEvent(err_msg)
348 sys.exit(1) 350 sys.exit(1)
349 branch = rp.GetBranch("default") 351 branch = rp.GetBranch("default")
350 branch.merge = remote_ref 352 branch.merge = remote_ref
diff --git a/subcmds/rebase.py b/subcmds/rebase.py
index dc4f5805..c0e83adf 100644
--- a/subcmds/rebase.py
+++ b/subcmds/rebase.py
@@ -206,7 +206,9 @@ branch but need to incorporate new upstream changes "underneath" them.
206 ret += 1 206 ret += 1
207 207
208 if ret: 208 if ret:
209 out.fail("%i projects had errors", ret) 209 msg_fmt = "%d projects had errors"
210 self.git_event_log.ErrorEvent(msg_fmt % (ret), msg_fmt)
211 out.fail(msg_fmt, ret)
210 out.nl() 212 out.nl()
211 213
212 return ret 214 return ret
diff --git a/subcmds/start.py b/subcmds/start.py
index d7772b33..9baf4256 100644
--- a/subcmds/start.py
+++ b/subcmds/start.py
@@ -168,4 +168,6 @@ revision specified in the manifest.
168 % (p.RelPath(local=opt.this_manifest_only), nb), 168 % (p.RelPath(local=opt.this_manifest_only), nb),
169 file=sys.stderr, 169 file=sys.stderr,
170 ) 170 )
171 msg_fmt = "cannot start %d project(s)"
172 self.git_event_log.ErrorEvent(msg_fmt % (len(err)), msg_fmt)
171 sys.exit(1) 173 sys.exit(1)
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 68a076df..8f73d27f 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -1695,32 +1695,29 @@ later is required to fix a server side protocol bug.
1695 1695
1696 # If we saw an error, exit with code 1 so that other scripts can check. 1696 # If we saw an error, exit with code 1 so that other scripts can check.
1697 if err_event.is_set(): 1697 if err_event.is_set():
1698 print("\nerror: Unable to fully sync the tree.", file=sys.stderr) 1698 # Add a new line so it's easier to read.
1699 print("\n", file=sys.stderr)
1700
1701 def print_and_log(err_msg):
1702 self.git_event_log.ErrorEvent(err_msg)
1703 print(err_msg, file=sys.stderr)
1704
1705 print_and_log("error: Unable to fully sync the tree")
1699 if err_network_sync: 1706 if err_network_sync:
1700 print( 1707 print_and_log("error: Downloading network changes failed.")
1701 "error: Downloading network changes failed.",
1702 file=sys.stderr,
1703 )
1704 if err_update_projects: 1708 if err_update_projects:
1705 print( 1709 print_and_log("error: Updating local project lists failed.")
1706 "error: Updating local project lists failed.",
1707 file=sys.stderr,
1708 )
1709 if err_update_linkfiles: 1710 if err_update_linkfiles:
1710 print( 1711 print_and_log("error: Updating copyfiles or linkfiles failed.")
1711 "error: Updating copyfiles or linkfiles failed.",
1712 file=sys.stderr,
1713 )
1714 if err_checkout: 1712 if err_checkout:
1715 print( 1713 print_and_log("error: Checking out local projects failed.")
1716 "error: Checking out local projects failed.",
1717 file=sys.stderr,
1718 )
1719 if err_results: 1714 if err_results:
1715 # Don't log repositories, as it may contain sensitive info.
1720 print( 1716 print(
1721 "Failing repos:\n%s" % "\n".join(err_results), 1717 "Failing repos:\n%s" % "\n".join(err_results),
1722 file=sys.stderr, 1718 file=sys.stderr,
1723 ) 1719 )
1720 # Not useful to log.
1724 print( 1721 print(
1725 'Try re-running with "-j1 --fail-fast" to exit at the first ' 1722 'Try re-running with "-j1 --fail-fast" to exit at the first '
1726 "error.", 1723 "error.",
diff --git a/subcmds/upload.py b/subcmds/upload.py
index 63216afb..f9c5e7f8 100644
--- a/subcmds/upload.py
+++ b/subcmds/upload.py
@@ -657,6 +657,7 @@ Gerrit Code Review: https://www.gerritcodereview.com/
657 657
658 branch.uploaded = True 658 branch.uploaded = True
659 except UploadError as e: 659 except UploadError as e:
660 self.git_event_log.ErrorEvent("upload error: " + str(e))
660 branch.error = e 661 branch.error = e
661 branch.uploaded = False 662 branch.uploaded = False
662 have_errors = True 663 have_errors = True