|
15 | 15 | import glob
|
16 | 16 | import hashlib
|
17 | 17 | import os.path
|
18 |
| - |
19 | 18 | from typing import Callable, Iterable
|
20 | 19 |
|
21 |
| -from coverage.exceptions import CoverageException, NoDataError |
| 20 | +from coverage.exceptions import CoverageException, DataFileOrDirectoryNotFoundError, \ |
| 21 | + NoDataFilesFoundError, UnusableDataFilesError |
22 | 22 | from coverage.files import PathAliases
|
23 | 23 | from coverage.misc import Hasher, file_be_gone, human_sorted, plural
|
24 | 24 | from coverage.sqldata import CoverageData
|
@@ -82,12 +82,15 @@ def combinable_files(data_file: str, data_paths: Iterable[str] | None = None) ->
|
82 | 82 | pattern = glob.escape(os.path.join(os.path.abspath(p), local)) +".*"
|
83 | 83 | files_to_combine.extend(glob.glob(pattern))
|
84 | 84 | else:
|
85 |
| - raise NoDataError(f"Couldn't combine from non-existent path '{p}'") |
| 85 | + raise DataFileOrDirectoryNotFoundError.new_for_data_file_or_directory(p, is_combining=True) |
86 | 86 |
|
87 | 87 | # SQLite might have made journal files alongside our database files.
|
88 | 88 | # We never want to combine those.
|
89 | 89 | files_to_combine = [fnm for fnm in files_to_combine if not fnm.endswith("-journal")]
|
90 | 90 |
|
| 91 | + if not files_to_combine: |
| 92 | + raise NoDataFilesFoundError.new_for_data_directory(data_dir) |
| 93 | + |
91 | 94 | # Sorting isn't usually needed, since it shouldn't matter what order files
|
92 | 95 | # are combined, but sorting makes tests more predictable, and makes
|
93 | 96 | # debugging more understandable when things go wrong.
|
@@ -129,10 +132,12 @@ def combine_parallel_data(
|
129 | 132 | `message` is a function to use for printing messages to the user.
|
130 | 133 |
|
131 | 134 | """
|
132 |
| - files_to_combine = combinable_files(data.base_filename(), data_paths) |
133 |
| - |
134 |
| - if strict and not files_to_combine: |
135 |
| - raise NoDataError("No data to combine") |
| 135 | + try: |
| 136 | + files_to_combine = combinable_files(data.base_filename(), data_paths) |
| 137 | + except NoDataFilesFoundError: |
| 138 | + if strict: |
| 139 | + raise |
| 140 | + return |
136 | 141 |
|
137 | 142 | file_hashes = set()
|
138 | 143 | combined_any = False
|
@@ -190,7 +195,7 @@ def combine_parallel_data(
|
190 | 195 | file_be_gone(f)
|
191 | 196 |
|
192 | 197 | if strict and not combined_any:
|
193 |
| - raise NoDataError("No usable data files") |
| 198 | + raise UnusableDataFilesError.new_for_data_files(*files_to_combine) |
194 | 199 |
|
195 | 200 |
|
196 | 201 | def debug_data_file(filename: str) -> None:
|
|
0 commit comments