sync: Share final error handling logic between sync modes
Bug: 421935613 Change-Id: I4604a83943dbbd71d979158d7a1c4b8c243347d2
This commit is contained in:
parent
37336085c4
commit
e87656f6e7
1 changed files with 40 additions and 21 deletions
|
@ -2127,29 +2127,48 @@ 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():
|
||||||
|
self._ReportSyncErrors(
|
||||||
|
errors,
|
||||||
|
err_network=err_network_sync,
|
||||||
|
err_checkout=err_checkout,
|
||||||
|
err_update_projects=err_update_projects,
|
||||||
|
err_update_linkfiles=err_update_linkfiles,
|
||||||
|
failing_checkout_projects=err_results,
|
||||||
|
)
|
||||||
|
|
||||||
def print_and_log(err_msg):
|
def _ReportSyncErrors(
|
||||||
self.git_event_log.ErrorEvent(err_msg)
|
self,
|
||||||
logger.error("%s", err_msg)
|
errors: List[Exception],
|
||||||
|
err_network: bool,
|
||||||
|
err_checkout: bool,
|
||||||
|
err_update_projects: bool,
|
||||||
|
err_update_linkfiles: bool,
|
||||||
|
failing_checkout_projects: List[str],
|
||||||
|
):
|
||||||
|
"""Common error reporting for sync failures."""
|
||||||
|
def print_and_log(err_msg):
|
||||||
|
self.git_event_log.ErrorEvent(err_msg)
|
||||||
|
logger.error("%s", err_msg)
|
||||||
|
|
||||||
print_and_log("error: Unable to fully sync the tree")
|
print_and_log("error: Unable to fully sync the tree")
|
||||||
if err_network_sync:
|
if err_network:
|
||||||
print_and_log("error: Downloading network changes failed.")
|
print_and_log("error: Downloading network changes failed.")
|
||||||
if err_update_projects:
|
if err_update_projects:
|
||||||
print_and_log("error: Updating local project lists failed.")
|
print_and_log("error: Updating local project lists failed.")
|
||||||
if err_update_linkfiles:
|
if err_update_linkfiles:
|
||||||
print_and_log("error: Updating copyfiles or linkfiles failed.")
|
print_and_log("error: Updating copyfiles or linkfiles failed.")
|
||||||
if err_checkout:
|
if err_checkout:
|
||||||
print_and_log("error: Checking out local projects failed.")
|
print_and_log("error: Checking out local projects failed.")
|
||||||
if err_results:
|
if failing_checkout_projects:
|
||||||
# Don't log repositories, as it may contain sensitive info.
|
# Don't log repositories, as it may contain sensitive info.
|
||||||
logger.error("Failing repos:\n%s", "\n".join(err_results))
|
logger.error(
|
||||||
# Not useful to log.
|
"Failing repos:\n%s", "\n".join(failing_checkout_projects)
|
||||||
logger.error(
|
)
|
||||||
'Try re-running with "-j1 --fail-fast" to exit at the first '
|
# Not useful to log.
|
||||||
"error."
|
logger.error(
|
||||||
)
|
'Try re-running with "-j1 --fail-fast" to exit at the first error.'
|
||||||
raise SyncError(aggregate_errors=errors)
|
)
|
||||||
|
raise SyncError(aggregate_errors=errors)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _SyncOneProject(cls, opt, project_index, project) -> _SyncResult:
|
def _SyncOneProject(cls, opt, project_index, project) -> _SyncResult:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue