diff options
author | Mike Frysinger <vapier@google.com> | 2017-09-14 12:37:01 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2017-09-14 17:24:24 +0000 |
commit | f363ab9d13f3b8178b49f7a61a25f26aca19b6f6 (patch) | |
tree | d47d6e02b140d067ffde3d3a472696ea30088343 | |
parent | 6abc478494f3bfb112e1d2e4ab1ff7e941667828 (diff) | |
download | repohooks-f363ab9d13f3b8178b49f7a61a25f26aca19b6f6.tar.gz |
clang-format: fail gracefully when clang-format itself aborts
If the clang-format program aborts/crashes, make sure we don't dump
a raw traceback as users might think it's a problem with repohooks.
Bug: 65671402
Test: Ran clang-format on some files
Change-Id: Ibfccac60ad550146d6d44c23c7566361e8add260
-rwxr-xr-x | tools/clang-format.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/tools/clang-format.py b/tools/clang-format.py index ac9e826..998eb49 100755 --- a/tools/clang-format.py +++ b/tools/clang-format.py @@ -78,7 +78,15 @@ def main(argv): cmd.extend(['%s^' % opts.commit, opts.commit]) cmd.extend(['--'] + opts.files) - stdout = rh.utils.run_command(cmd, capture_output=True).output + # Fail gracefully if clang-format itself aborts/fails. + try: + result = rh.utils.run_command(cmd, capture_output=True) + except rh.utils.RunCommandError as e: + print('clang-format failed:\n%s' % (e,), file=sys.stderr) + print('\nPlease report this to the clang team.', file=sys.stderr) + return 1 + + stdout = result.output if stdout.rstrip('\n') == 'no modified files to format': # This is always printed when only files that clang-format does not # understand were modified. |