fix: raise ChordFormatError when detokenize produces empty bars

A sequence of only metadata tokens followed by EOS would silently return a
ChordPeriod with bars=[], which would later crash or produce an empty .chord
file. Now raises immediately with a descriptive message. Added a failing-then-
passing test to cover this path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-04 15:00:45 +03:00
parent d09a08d553
commit 1a63b8e4d8
2 changed files with 21 additions and 0 deletions
+6
View File
@@ -508,6 +508,12 @@ def detokenize_to_period(token_ids: list[int]) -> ChordPeriod:
pos_in_bar, positions_per_bar,
)
if not bars:
raise ChordFormatError(
"token sequence produced no complete bars "
f"(last partial bar had {pos_in_bar}/{positions_per_bar} positions)"
)
return ChordPeriod(
title="detokenized",
key=key,