mirror of
https://github.com/kbenestad/mdcms.git
synced 2026-06-18 07:24:31 +00:00
Fix: raise on config.yml parse errors instead of silently returning empty dict
A YAML parse error in config.yml (e.g. a stray tab character) caused
read_config to swallow the exception and return {}, disabling categories
and producing a broken nav.yml with no variants fields and wrong filenames.
read_config now raises ClickException on both OSError and YAMLError.
Documented in docs/knownbugs.md and docs/unreleased.md.
https://claude.ai/code/session_01Xs5GyREFhjWxhS1UhW2wA8
This commit is contained in:
parent
7b2d54da57
commit
431b1c054c
3 changed files with 28 additions and 2 deletions
15
docs/knownbugs.md
Normal file
15
docs/knownbugs.md
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
# Known bugs
|
||||||
|
|
||||||
|
Bugs that have been identified but not yet fixed. Fixed bugs are moved to the release notes.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Fixed in development (not yet released)
|
||||||
|
|
||||||
|
### `config.yml` YAML parse errors were silently swallowed
|
||||||
|
|
||||||
|
**Symptom:** A malformed `config.yml` (e.g. a stray tab character, which YAML forbids as a token starter) caused `read_config` to catch the `YAMLError` and return an empty dict. The build would proceed with no config — categories disabled, no default category code — producing a `nav.yml` that omitted `variants` fields and listed category variant files (e.g. `page.current.md`) as plain pages. Pages with category variants would not appear in the sidebar.
|
||||||
|
|
||||||
|
**Root cause:** `read_config` caught `(OSError, yaml.YAMLError)` in a single block and silently returned `{}` on any error.
|
||||||
|
|
||||||
|
**Fix:** `read_config` now raises `click.ClickException` on both `OSError` and `yaml.YAMLError`, aborting the build with a descriptive error message instead of continuing with an empty config.
|
||||||
|
|
@ -40,3 +40,11 @@ After rebuilding a site with `mdcms build`, affected post entries in `nav.yml` g
|
||||||
In `search.json`, these entries carry `"category": null` instead of the default category code. This is what tells the renderer to include them universally.
|
In `search.json`, these entries carry `"category": null` instead of the default category code. This is what tells the renderer to include them universally.
|
||||||
|
|
||||||
A rebuild is required for existing sites to pick up the change.
|
A rebuild is required for existing sites to pick up the change.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Fix: `config.yml` YAML parse errors now abort the build with a clear message
|
||||||
|
|
||||||
|
A malformed `config.yml` (e.g. a stray tab character, which YAML forbids as a token starter) previously caused `read_config` to silently return an empty dict. The build would proceed with no config — categories disabled, no default category code — producing a broken `nav.yml` with wrong filenames and missing `variants` fields, so category-variant pages would not appear in the sidebar.
|
||||||
|
|
||||||
|
`read_config` now raises `ClickException` on both `OSError` and `yaml.YAMLError`, aborting the build with a descriptive error message instead of continuing silently with an empty config.
|
||||||
|
|
|
||||||
7
mdcms.py
7
mdcms.py
|
|
@ -113,9 +113,12 @@ def read_config(site_path: Path) -> dict:
|
||||||
return {}
|
return {}
|
||||||
try:
|
try:
|
||||||
text = config_file.read_text(encoding="utf-8")
|
text = config_file.read_text(encoding="utf-8")
|
||||||
|
except OSError as e:
|
||||||
|
raise click.ClickException(f"Could not read config.yml: {e}")
|
||||||
|
try:
|
||||||
return yaml.safe_load(text) or {}
|
return yaml.safe_load(text) or {}
|
||||||
except (OSError, yaml.YAMLError):
|
except yaml.YAMLError as e:
|
||||||
return {}
|
raise click.ClickException(f"config.yml is not valid YAML: {e}")
|
||||||
|
|
||||||
|
|
||||||
def get_category_info(cfg: dict) -> dict:
|
def get_category_info(cfg: dict) -> dict:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue