aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generat3d/config.py4
-rw-r--r--tests/test_config.py9
2 files changed, 13 insertions, 0 deletions
diff --git a/generat3d/config.py b/generat3d/config.py
index 9ea7266..804723f 100644
--- a/generat3d/config.py
+++ b/generat3d/config.py
@@ -39,6 +39,8 @@ def library_roots(cli_roots, path=None):
data = tomllib.load(f)
except tomllib.TOMLDecodeError as e:
raise Error(f"{path}: {e}") from None
+ except OSError as e:
+ raise Error(f"{path}: {e.strerror or e}") from None
unknown = sorted(set(data) - KEYS)
if unknown:
raise Error(f"{path}: unknown keys: {', '.join(unknown)}")
@@ -49,6 +51,8 @@ def library_roots(cli_roots, path=None):
raise Error(f"no library roots: pass -L or set library_roots in {path}")
out = []
for r in roots:
+ if not r.strip():
+ raise Error("empty library root")
p = Path(r).expanduser()
if not p.is_dir():
raise Error(f"library root not found: {p}")
diff --git a/tests/test_config.py b/tests/test_config.py
index d1ad0d2..72ed0f6 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -79,3 +79,12 @@ class ConfigTest(unittest.TestCase):
del os.environ["XDG_CONFIG_HOME"]
else:
os.environ["XDG_CONFIG_HOME"] = old
+
+ def test_unreadable_config_is_fatal(self):
+ self.cfg.mkdir()
+ with self.assertRaisesRegex(Error, "config.toml"):
+ library_roots([], self.cfg)
+
+ def test_empty_library_root_is_fatal(self):
+ with self.assertRaisesRegex(Error, "empty library root"):
+ library_roots([""], self.cfg)