From df9d95c379a5b59877a9f9fc609597fedb8390fb Mon Sep 17 00:00:00 2001 From: Sai Asish Y Date: Wed, 26 Aug 2026 02:58:29 -0700 Subject: [PATCH] Raise a clear error when the settings file does not exist Signed-off-by: Sai Asish Y --- pelican/settings.py | 4 ++++ pelican/tests/test_settings.py | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/pelican/settings.py b/pelican/settings.py index 45957fd0..b4b50021 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -16,7 +16,11 @@ from pelican.paginator import PaginationRule def load_source(name: str, path: str) -> ModuleType: + if not os.path.isfile(path): + raise FileNotFoundError(f"Settings file not found: {path}") spec = importlib.util.spec_from_file_location(name, path) + if spec is None or spec.loader is None: + raise ImportError(f"Could not load settings file: {path}") mod = importlib.util.module_from_spec(spec) sys.modules[name] = mod spec.loader.exec_module(mod) diff --git a/pelican/tests/test_settings.py b/pelican/tests/test_settings.py index 54167e63..8cdd49c6 100644 --- a/pelican/tests/test_settings.py +++ b/pelican/tests/test_settings.py @@ -57,6 +57,12 @@ class TestSettingsConfiguration(unittest.TestCase): self.maxDiff = None self.assertDictEqual(settings, expected) + def test_read_settings_missing_file(self): + # A missing settings file should raise a clear FileNotFoundError + # rather than an obscure AttributeError from the import machinery. + missing = join(self.PATH, "does_not_exist") + self.assertRaises(FileNotFoundError, read_settings, missing) + def test_settings_return_independent(self): # Make sure that the results from one settings call doesn't # effect past or future instances.