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>
changes/26/1277426/3
Edward Lemur 7 years ago committed by Commit Bot
parent 2fddb95698
commit 47faa068e8

@ -47,6 +47,10 @@ GERRIT_PROTOCOL = 'https'
# 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 @@ def ReadHttpResponse(conn, accept_statuses=frozenset([200])):
# 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)

@ -3170,6 +3170,15 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
try:
# TODO(crbug.com/881860): Remove.
# Clear the log after each git-cl upload run by setting mode='w'.
handler = logging.FileHandler(gerrit_util.GERRIT_ERR_LOG_FILE, mode='w')
handler.setFormatter(logging.Formatter('%(asctime)s %(message)s'))
GERRIT_ERR_LOGGER.addHandler(handler)
GERRIT_ERR_LOGGER.setLevel(logging.INFO)
# Don't propagate to root logger, so that logs are not printed.
GERRIT_ERR_LOGGER.propagate = 0
# Get interesting headers from git push, to be displayed to the user if
# subsequent Gerrit RPC calls fail.
env = os.environ.copy()
@ -6258,16 +6267,6 @@ class OptionParser(optparse.OptionParser):
format='[%(levelname).1s%(asctime)s %(process)d %(thread)d '
'%(filename)s] %(message)s')
# TODO(crbug.com/881860): Remove.
# Clear the log after each git-cl run by setting mode='w'.
handler = logging.FileHandler(gerrit_util.GERRIT_ERR_LOG_FILE, mode='w')
handler.setFormatter(logging.Formatter('%(asctime)s %(message)s'))
GERRIT_ERR_LOGGER.addHandler(handler)
GERRIT_ERR_LOGGER.setLevel(logging.INFO)
# Don't propagate to root logger, so that logs are not printed.
GERRIT_ERR_LOGGER.propagate = 0
return options, args

Loading…
Cancel
Save