git-cl: Make request to upload logs more visible.
Print the message asking the user to upload gerrit logs for git-cl upload
failures after the exception.
Also, initialize the error logger only for git-cl upload, so that the
headers are not overwritten unless git-cl upload is executed again.
Bug: 881860
Change-Id: I8e63432eecca5253e56096e3ad0218eec4058e12
Reviewed-on: https://chromium-review.googlesource.com/c/1277426
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: Andrii Shyshkalov <tandrii@chromium.org>
diff --git a/gerrit_util.py b/gerrit_util.py
index f69dcbc..565ebdb 100644
--- a/gerrit_util.py
+++ b/gerrit_util.py
@@ -47,6 +47,10 @@
# TODO(crbug.com/881860): Remove.
GERRIT_ERR_LOGGER = logging.getLogger('GerritErrorLogs')
GERRIT_ERR_LOG_FILE = os.path.join(tempfile.gettempdir(), 'GerritHeaders.txt')
+GERRIT_ERR_MESSAGE = (
+ 'If you see this when running \'git cl upload\', please report this to '
+ 'https://crbug.com/881860, and attach the failures in %s.\n' %
+ GERRIT_ERR_LOG_FILE)
INTERESTING_HEADERS = frozenset([
'x-google-backends',
'x-google-errorfiltertrace',
@@ -480,15 +484,14 @@
# end of retries loop
if failed:
- LOGGER.warn(
- 'If you see this when running \'git cl upload\', consider '
- 'reporting this to https://crbug.com/881860, and please attach the '
- 'failures in %s.\n', GERRIT_ERR_LOG_FILE)
+ LOGGER.warn(GERRIT_ERR_MESSAGE)
if response.status not in accept_statuses:
if response.status in (401, 403):
print('Your Gerrit credentials might be misconfigured. Try: \n'
' git cl creds-check')
reason = '%s: %s' % (response.reason, contents)
+ if failed:
+ reason += '\n' + GERRIT_ERR_MESSAGE
raise GerritError(response.status, reason)
return StringIO(contents)