From f363ab9d13f3b8178b49f7a61a25f26aca19b6f6 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 14 Sep 2017 12:37:01 -0400 Subject: 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 --- tools/clang-format.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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. -- cgit v1.2.3