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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user