Commit 740825ec authored by Josip Sokcevic's avatar Josip Sokcevic Committed by LUCI CQ

Detect uploadvalidator error message

If git push refs/for/ errors out, inspect stdout message to detect
uploadvalidator rejection. If present, present user a solution.

R=ajp@google.com

Change-Id: I70aee7615f3d905127a31bd5679968ade75c234a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2888475Reviewed-by: 's avatarAndy Perelson <ajp@chromium.org>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
parent f5c6d8a2
......@@ -585,6 +585,10 @@ def CheckCallAndFilter(args, print_stdout=False, filter_fn=None,
sleep_interval = RETRY_INITIAL_SLEEP
run_cwd = kwargs.get('cwd', os.getcwd())
# Store the output of the command regardless of the value of print_stdout or
# filter_fn.
command_output = io.BytesIO()
for attempt in range(RETRY_MAX + 1):
# If our stdout is a terminal, then pass in a psuedo-tty pipe to our
# subprocess when filtering its output. This makes the subproc believe
......@@ -603,10 +607,6 @@ def CheckCallAndFilter(args, print_stdout=False, filter_fn=None,
GClientChildren.add(kid)
# Store the output of the command regardless of the value of print_stdout or
# filter_fn.
command_output = io.BytesIO()
# Passed as a list for "by ref" semantics.
needs_header = [show_header]
if always_show_header:
......@@ -667,11 +667,12 @@ def CheckCallAndFilter(args, print_stdout=False, filter_fn=None,
print("WARNING: subprocess '%s' in %s failed; will retry after a short "
'nap...' % (' '.join('"%s"' % x for x in args), run_cwd))
command_output = io.BytesIO()
time.sleep(sleep_interval)
sleep_interval *= 2
raise subprocess2.CalledProcessError(
rv, args, kwargs.get('cwd', None), None, None)
rv, args, kwargs.get('cwd', None), command_output.getvalue(), None)
class GitFilter(object):
......
......@@ -2232,6 +2232,17 @@ class Changelist(object):
push_stdout = push_stdout.decode('utf-8', 'replace')
except subprocess2.CalledProcessError as e:
push_returncode = e.returncode
if 'blocked keyword' in str(e.stdout):
raise GitPushError(
'Failed to create a change, very likely due to blocked keyword. '
'Please examine output above for the reason of the failure.\n'
'If this is a false positive, you can try to bypass blocked '
'keyword by using push option '
'-o uploadvalidator~skip, e.g.:\n'
'git cl upload -o uploadvalidator~skip\n\n'
'If git-cl is not working correctly, file a bug under the '
'Infra>SDK component.')
raise GitPushError(
'Failed to create a change. Please examine output above for the '
'reason of the failure.\n'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment