|
6 | 6 | from typing import Optional, List, Dict, Tuple, cast |
7 | 7 | import shutil |
8 | 8 |
|
9 | | -from ..common_fs import FileObj |
| 9 | +from ..common_fs import FileObj, FileIOTimeout |
10 | 10 | from ..common_fs.file_filter import TidyFileFilter, FormatFileFilter |
11 | 11 | from ..loggers import start_log_group, end_log_group, worker_log_init, logger |
12 | 12 | from .clang_tidy import run_clang_tidy, TidyAdvice |
@@ -45,34 +45,52 @@ def _run_on_single_file( |
45 | 45 | args: Args, |
46 | 46 | ) -> Tuple[str, str, Optional[TidyAdvice], Optional[FormatAdvice]]: |
47 | 47 | log_stream = worker_log_init(log_lvl) |
| 48 | + filename = Path(file.name).as_posix() |
48 | 49 |
|
49 | | - format_advice = None |
| 50 | + format_advice = FormatAdvice(filename) |
50 | 51 | if format_cmd is not None and ( |
51 | 52 | format_filter is None or format_filter.is_source_or_ignored(file.name) |
52 | 53 | ): |
53 | | - format_advice = run_clang_format( |
54 | | - command=format_cmd, |
55 | | - file_obj=file, |
56 | | - style=args.style, |
57 | | - lines_changed_only=args.lines_changed_only, |
58 | | - format_review=args.format_review, |
59 | | - ) |
| 54 | + try: |
| 55 | + format_advice = run_clang_format( |
| 56 | + command=format_cmd, |
| 57 | + file_obj=file, |
| 58 | + style=args.style, |
| 59 | + lines_changed_only=args.lines_changed_only, |
| 60 | + format_review=args.format_review, |
| 61 | + ) |
| 62 | + except FileIOTimeout: # pragma: no cover |
| 63 | + logger.error( |
| 64 | + "Failed to read or write contents of %s when running clang-format", |
| 65 | + filename, |
| 66 | + ) |
| 67 | + except OSError: # pragma: no cover |
| 68 | + logger.error( |
| 69 | + "Failed to open the file %s when running clang-format", filename |
| 70 | + ) |
60 | 71 |
|
61 | | - tidy_note = None |
| 72 | + tidy_note = TidyAdvice([]) |
62 | 73 | if tidy_cmd is not None and ( |
63 | 74 | tidy_filter is None or tidy_filter.is_source_or_ignored(file.name) |
64 | 75 | ): |
65 | | - tidy_note = run_clang_tidy( |
66 | | - command=tidy_cmd, |
67 | | - file_obj=file, |
68 | | - checks=args.tidy_checks, |
69 | | - lines_changed_only=args.lines_changed_only, |
70 | | - database=args.database, |
71 | | - extra_args=args.extra_arg, |
72 | | - db_json=db_json, |
73 | | - tidy_review=args.tidy_review, |
74 | | - style=args.style, |
75 | | - ) |
| 76 | + try: |
| 77 | + tidy_note = run_clang_tidy( |
| 78 | + command=tidy_cmd, |
| 79 | + file_obj=file, |
| 80 | + checks=args.tidy_checks, |
| 81 | + lines_changed_only=args.lines_changed_only, |
| 82 | + database=args.database, |
| 83 | + extra_args=args.extra_arg, |
| 84 | + db_json=db_json, |
| 85 | + tidy_review=args.tidy_review, |
| 86 | + style=args.style, |
| 87 | + ) |
| 88 | + except FileIOTimeout: # pragma: no cover |
| 89 | + logger.error( |
| 90 | + "Failed to Read/Write contents of %s when running clang-tidy", filename |
| 91 | + ) |
| 92 | + except OSError: # pragma: no cover |
| 93 | + logger.error("Failed to open the file %s when running clang-tidy", filename) |
76 | 94 |
|
77 | 95 | return file.name, log_stream.getvalue(), tidy_note, format_advice |
78 | 96 |
|
|
0 commit comments