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): event["value"] = value self._log.append(event) - def ErrorEvent(self, msg, fmt): + def ErrorEvent(self, msg, fmt=None): """Append a 'error' event to the current log.""" error_event = self._CreateEventDict("error") + if fmt is None: + fmt = msg error_event["msg"] = msg error_event["fmt"] = fmt 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. quiet=opt.quiet, ) except wrapper.CloneFailure: + err_msg = "fatal: double check your --repo-rev setting." print( - "fatal: double check your --repo-rev setting.", + err_msg, file=sys.stderr, ) + self.git_event_log.ErrorEvent(err_msg) sys.exit(1) branch = rp.GetBranch("default") 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. ret += 1 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() 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. % (p.RelPath(local=opt.this_manifest_only), nb), file=sys.stderr, ) + msg_fmt = "cannot start %d project(s)" + self.git_event_log.ErrorEvent(msg_fmt % (len(err)), msg_fmt) 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. # If we saw an error, exit with code 1 so that other scripts can check. 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: - print( - "error: Downloading network changes failed.", - file=sys.stderr, - ) + print_and_log("error: Downloading network changes failed.") if err_update_projects: - print( - "error: Updating local project lists failed.", - file=sys.stderr, - ) + print_and_log("error: Updating local project lists failed.") if err_update_linkfiles: - print( - "error: Updating copyfiles or linkfiles failed.", - file=sys.stderr, - ) + print_and_log("error: Updating copyfiles or linkfiles failed.") if err_checkout: - print( - "error: Checking out local projects failed.", - file=sys.stderr, - ) + print_and_log("error: Checking out local projects failed.") if err_results: + # Don't log repositories, as it may contain sensitive info. print( "Failing repos:\n%s" % "\n".join(err_results), file=sys.stderr, ) + # Not useful to log. print( 'Try re-running with "-j1 --fail-fast" to exit at the first ' "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/ branch.uploaded = True except UploadError as e: + self.git_event_log.ErrorEvent("upload error: " + str(e)) branch.error = e branch.uploaded = False have_errors = True