Commit 673e8ede authored by Josip Sokcevic's avatar Josip Sokcevic Committed by LUCI CQ

Surface yapf format errors when written to stderr

When CheckPatchFormatted presubmited canned check is executed, it runs
git cl format with --dry-run. When dry-run is used, exit codes are
ignored and we rely on only on stdout message to detect if formatting is
needed or not. This itself is wrong, but changing this will likely
require significant redesign.

This patch appends stderr output to stdout message on non-zero exit code
and therefore allowing git cl format to actually exit with code 2.

R=gavinmak@google.com

Fixed: 1264111
Change-Id: I5eccf34f533640fd93209c97d1c8d9c85bb94d83
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3249191
Auto-Submit: Josip Sokcevic <sokcevic@google.com>
Reviewed-by: 's avatarGavin Mak <gavinmak@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
parent 869118a1
......@@ -185,7 +185,10 @@ def RunCommand(args, error_ok=False, error_message=None, shell=False, **kwargs):
if not error_ok:
message = error_message or e.stdout.decode('utf-8', 'replace') or ''
DieWithError('Command "%s" failed.\n%s' % (' '.join(args), message))
return e.stdout.decode('utf-8', 'replace')
out = e.stdout.decode('utf-8', 'replace')
if e.stderr:
out += e.stderr.decode('utf-8', 'replace')
return out
def RunGit(args, **kwargs):
......@@ -5282,6 +5285,7 @@ def CMDformat(parser, args):
# Will return non-zero exit code if non-empty diff.
stdout = RunCommand(cmd,
error_ok=True,
stderr=subprocess2.PIPE,
cwd=top_dir,
shell=sys.platform.startswith('win32'))
if opts.diff:
......
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