From a47203f8a542805070a152980bbb4fae13b6697f Mon Sep 17 00:00:00 2001 From: Noam Bernstein Date: Thu, 10 Oct 2024 09:04:19 -0400 Subject: [PATCH] Give better error message when ConfigSet is passed a file that does not exist (or glob that matches nothing) --- wfl/configset.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wfl/configset.py b/wfl/configset.py index c1a6c74a..f0313a9b 100644 --- a/wfl/configset.py +++ b/wfl/configset.py @@ -85,6 +85,8 @@ def __init__(self, items, *, file_root=None, read_kwargs={}, _open_reader=None, # single item, could be a simple filename or a glob. Former needs to be stored as # Path, latter as list(Path) items_expanded = [Path(f) for f in sorted(glob.glob(str(file_root / items), recursive=True))] + if len(items_expanded) == 0: + raise ValueError(f"got file '{file_root}' / '{items}' that does not exist") if len(items_expanded) == 1 and file_root / items == items_expanded[0]: self.items = file_root / items else: @@ -95,7 +97,10 @@ def __init__(self, items, *, file_root=None, read_kwargs={}, _open_reader=None, assert isinstance(file_path, (str, Path)) if file_root != Path("") and Path(file_path).is_absolute(): raise ValueError(f"Got file_root but file {file_path} is an absolute path") - self.items.extend([Path(f) for f in sorted(glob.glob(str(file_root / file_path), recursive=True))]) + items_expanded = [Path(f) for f in sorted(glob.glob(str(file_root / file_path), recursive=True))] + if len(items_expanded) == 0: + raise ValueError(f"got file '{file_root}' / '{file_path}' that does not exist") + self.items.extend(items_expanded) elif isinstance(items[0], ConfigSet): self.items = [] for item in items: