Skip to content

fix(kb): report an impossible front-matter date instead of crashing - #66

Merged
rehan-remade merged 3 commits into
rehan-remade:mainfrom
kevin9327:fix/kb-invalid-date
Oct 5, 2026
Merged

rehan-remade merged 3 commits into
rehan-remade:mainfrom
kevin9327:fix/kb-invalid-date

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

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

kevin9327 and others added 3 commits October 5, 2026 14:52
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Python 3.14 words the impossible-date ValueError differently from 3.12, so
the test checks um's own "front matter is not valid YAML" prefix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rehan-remade
rehan-remade merged commit 63f2f77 into rehan-remade:main Oct 5, 2026
@rehan-remade

Copy link
Copy Markdown
Owner

Thanks! Merged. I changed one line in the test: Python 3.14 words the date error differently ("day 31 must be in range 1..30 for month 9"), so it now checks for "front matter is not valid YAML" instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants