git-cl: catch "ReAuth is required" error and re-raise is properly

This CL updates _RunGitPushWithTraces to detect git credential-luci
"ReAuth is required" error and propagate it nicely to the caller.

Previously, the error is uncaught, and re-raised with nested exception
stacktrace. The result was an unhelpful traceback, where the true error
is at the top (part of git push stdout/stderr).

This CL now propagate the error with a clear GitPushError printed last
(which hopefully gets developer's attention).

Fixed: 445532843
Change-Id: I789a6902b59af2c9df92fc7d013829afc4154dc1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6954695
Commit-Queue: Scott Lee <ddoman@chromium.org>
Reviewed-by: Allen Li <ayatane@chromium.org>
Auto-Submit: Jiewei Qian <qjw@chromium.org>
Reviewed-by: Scott Lee <ddoman@chromium.org>
This commit is contained in:
Jiewei Qian
2025-09-22 15:06:26 -07:00
committed by LUCI CQ
parent 8ab2a5350f
commit 9b361d9c09

View File

@@ -3103,7 +3103,20 @@ class Changelist(object):
'git cl upload -o nokeycheck\n\n'
'If git-cl is not working correctly, file a bug under the '
'Infra>SDK component.')
if 'git credential-luci reauth' in str(e.stdout):
raise GitPushError(
'Failed to upload a change: ReAuth is required.\n'
'\n'
'Please ReAuth by running:\n'
' git credential-luci reauth\n'
'\n'
'If you are having trouble with ReAuth, see:\n'
'https://chromium.googlesource.com/chromium/src/+/main/docs/gerrit_reauth.md\n'
'\n'
'To bypass ReAuth for now, set LUCI_BYPASS_REAUTH '
'environment variable, then try again:\n'
' On Linux/Mac: export LUCI_BYPASS_REAUTH=1\n'
' On Windows: set LUCI_BYPASS_REAUTH=1\n')
raise GitPushError(
'Failed to create a change. Please examine output above for the '
'reason of the failure.\n'