diff --git a/gerrit_util.py b/gerrit_util.py index f69dcbcab1..565ebdbde6 100644 --- a/gerrit_util.py +++ b/gerrit_util.py @@ -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) diff --git a/git_cl.py b/git_cl.py index e85b241192..93e21989d4 100755 --- a/git_cl.py +++ b/git_cl.py @@ -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