[PR #66] [MERGED] fix(kb): report an impossible front-matter date instead of crashing #96

Closed
opened 2026-10-15 20:53:23 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/rehan-remade/universal-modder/pull/66
Author: @kevin9327
Created: 10/5/2026
Status: ✅ Merged
Merged: 10/5/2026
Merged by: @rehan-remade

Base: main ← Head: fix/kb-invalid-date


📝 Commits (3)

  • 2118fed fix(kb): report an impossible front-matter date instead of crashing
  • eecddfc Merge main into fix/kb-invalid-date and regenerate the kb index
  • a12cc7a test: check the error prefix, not Python's date message

📊 Changes

2 files changed (+13 additions, -1 deletions)

View changed files

📝 tests/test_um.py (+12 -0)
📝 um/kb.py (+1 -1)

📄 Description

kb.parse() only catches yaml.YAMLError, but PyYAML builds datetime.date objects for unquoted YYYY-MM-DD values. A day that doesn't exist (date: 2026-09-31, 2026-02-30, a swapped 2026-30-09) raises a plain ValueError from the constructor, so the error goes straight up to the user:

$ um kb check knowledge/techniques/t.md
Traceback (most recent call last):
  ...
  File ".../yaml/constructor.py", line 330, in construct_yaml_timestamp
    return datetime.date(year, month, day)
ValueError: day is out of range for month

Because notes() parses every file, one such note also crashes um kb search and um kb index for the whole knowledge base. check_note already has a friendly path for broken front matter (front matter is not valid YAML: ...), and the date check further down never gets a chance to run.

Change: catch ValueError next to yaml.YAMLError in parse(), so the note is reported as front matter is not valid YAML: day is out of range for month and the other notes still search and index.

Test: test_kb_impossible_date_is_reported_not_raised checks the note's failure message and runs search() and build_index() over a knowledge base containing it. It raises ValueError on main and passes with this change.

uv run --with pytest pytest -q tests   # 58 passed
./bin/um kb check --index               # PASS: 44 notes checked

Checklist

  • uv run --with pytest pytest -q tests passes (code)
  • no game files, extracted assets, decompiled code dumps or secrets
  • nothing that cheats other players or bypasses anti-cheat / DRM / ownership checks
  • authored by: @kevin9327

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/rehan-remade/universal-modder/pull/66 **Author:** [@kevin9327](https://github.com/kevin9327) **Created:** 10/5/2026 **Status:** ✅ Merged **Merged:** 10/5/2026 **Merged by:** [@rehan-remade](https://github.com/rehan-remade) **Base:** `main` ← **Head:** `fix/kb-invalid-date` --- ### 📝 Commits (3) - [`2118fed`](https://github.com/rehan-remade/universal-modder/commit/2118fed5cd6e2f079c638cab647716701ed4368e) fix(kb): report an impossible front-matter date instead of crashing - [`eecddfc`](https://github.com/rehan-remade/universal-modder/commit/eecddfc0304779af466725a82942025f69cd88f5) Merge main into fix/kb-invalid-date and regenerate the kb index - [`a12cc7a`](https://github.com/rehan-remade/universal-modder/commit/a12cc7abf889a88f0884e4fc0bbf60ea6cc9c0e4) test: check the error prefix, not Python's date message ### 📊 Changes **2 files changed** (+13 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_um.py` (+12 -0) 📝 `um/kb.py` (+1 -1) </details> ### 📄 Description `kb.parse()` only catches `yaml.YAMLError`, but PyYAML builds `datetime.date` objects for unquoted `YYYY-MM-DD` values. A day that doesn't exist (`date: 2026-09-31`, `2026-02-30`, a swapped `2026-30-09`) raises a plain `ValueError` from the constructor, so the error goes straight up to the user: ``` $ um kb check knowledge/techniques/t.md Traceback (most recent call last): ... File ".../yaml/constructor.py", line 330, in construct_yaml_timestamp return datetime.date(year, month, day) ValueError: day is out of range for month ``` Because `notes()` parses every file, one such note also crashes `um kb search` and `um kb index` for the whole knowledge base. `check_note` already has a friendly path for broken front matter (`front matter is not valid YAML: ...`), and the date check further down never gets a chance to run. Change: catch `ValueError` next to `yaml.YAMLError` in `parse()`, so the note is reported as `front matter is not valid YAML: day is out of range for month` and the other notes still search and index. Test: `test_kb_impossible_date_is_reported_not_raised` checks the note's failure message and runs `search()` and `build_index()` over a knowledge base containing it. It raises `ValueError` on `main` and passes with this change. ``` uv run --with pytest pytest -q tests # 58 passed ./bin/um kb check --index # PASS: 44 notes checked ``` **Checklist** - [x] `uv run --with pytest pytest -q tests` passes (code) - [x] no game files, extracted assets, decompiled code dumps or secrets - [x] nothing that cheats other players or bypasses anti-cheat / DRM / ownership checks - [x] authored by: @kevin9327 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-15 20:53:23 +00:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
rehan-remade/universal-modder#96
No description provided.