diff options
author | David Spickett <david.spickett@linaro.org> | 2021-03-05 11:13:58 +0000 |
---|---|---|
committer | David Spickett <david.spickett@linaro.org> | 2021-03-05 13:28:51 +0000 |
commit | 9c0069d836b326f3ae0b92a8f095b0707a944ed0 (patch) | |
tree | ded62884c2b49d4154011ba9ff5c4a7f12d09b85 /clang/tools/clang-format/clang-format-diff.py | |
parent | f677413071a2df10fbb68050624696fd4d4ae1cd (diff) | |
download | llvm-9c0069d836b326f3ae0b92a8f095b0707a944ed0.zip llvm-9c0069d836b326f3ae0b92a8f095b0707a944ed0.tar.gz llvm-9c0069d836b326f3ae0b92a8f095b0707a944ed0.tar.bz2 |
[clang-format] Improve clang-format-diff.py error message
Previously if we couldn't run the clang-format command
for some reason, you'd get an unhelpful error message:
```
OSError: [Errno 2] No such file or directory
```
Which doesn't tell you what was happening to cause this.
Catch the error and add the command we were attempting to run:
```
RuntimeError: Failed to run "<...>/clang-food <...>" - No such file or directory"
RuntimeError: Failed to run "<...>/clang-format <...>" - Permission denied"
```
Reviewed By: krasimir
Differential Revision: https://reviews.llvm.org/D98032
Diffstat (limited to 'clang/tools/clang-format/clang-format-diff.py')
-rwxr-xr-x | clang/tools/clang-format/clang-format-diff.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/clang/tools/clang-format/clang-format-diff.py b/clang/tools/clang-format/clang-format-diff.py index 6e653a1..efed816 100755 --- a/clang/tools/clang-format/clang-format-diff.py +++ b/clang/tools/clang-format/clang-format-diff.py @@ -103,11 +103,19 @@ def main(): command.extend(lines) if args.style: command.extend(['-style', args.style]) - p = subprocess.Popen(command, - stdout=subprocess.PIPE, - stderr=None, - stdin=subprocess.PIPE, - universal_newlines=True) + + try: + p = subprocess.Popen(command, + stdout=subprocess.PIPE, + stderr=None, + stdin=subprocess.PIPE, + universal_newlines=True) + except OSError as e: + # Give the user more context when clang-format isn't + # found/isn't executable, etc. + raise RuntimeError( + 'Failed to run "%s" - %s"' % (" ".join(command), e.strerror)) + stdout, stderr = p.communicate() if p.returncode != 0: sys.exit(p.returncode) |