From 131fc96381e112b0aa7a1012243e2ed5cfd3ec01 Mon Sep 17 00:00:00 2001 From: Josip Sokcevic Date: Fri, 12 May 2023 17:00:46 -0700 Subject: [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 Tested-by: Josip Sokcevic Commit-Queue: Josip Sokcevic Reviewed-by: Gavin Mak --- subcmds/sync.py | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'subcmds/sync.py') 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.", -- cgit v1.2.3-54-g00ecf