Skip to content

fix: raise TypeError for unrecognised MIDI messages in normalize_midi_messages - #495

Open
steps-re wants to merge 1 commit into
spotify:masterfrom
steps-re:fix/normalize-midi-messages-silent-drop
Open

fix: raise TypeError for unrecognised MIDI messages in normalize_midi_messages#495
steps-re wants to merge 1 commit into
spotify:masterfrom
steps-re:fix/normalize-midi-messages-silent-drop

Conversation

@steps-re

@steps-re steps-re commented Jul 8, 2026

Copy link
Copy Markdown

Fixes #489.

normalize_midi_messages() used an if / elif chain with no else branch, so any message that did not match the expected (bytes, float) tuple shape or a duck-typed mido.Message was silently dropped. The caller received a shorter output list with no indication that events were lost — wrong tuple length, missing timestamp, raw bytes, None, etc. all vanished without error.

Change:

  • Switched the for loop to enumerate() to track the message index.
  • Added an else branch that raises TypeError with the offending index and value.

Test:
Added test_normalize_midi_messages_raises_on_malformed in tests/test_midi_utils.py, covering five malformed shapes: 1-tuple (missing timestamp), 3-tuple (extra field), raw bytes, bare integer, and None.

…_messages

normalize_midi_messages() was silently dropping any MIDI message that did
not match the expected (bytes, float) tuple or duck-typed mido.Message
shape. Silent data loss made it impossible to detect malformed input —
e.g. a 1-tuple with a missing timestamp — without manually comparing
input and output lengths.

Switch the `for` loop to use `enumerate()` and add an `else` branch that
raises TypeError with the offending index and value, consistent with the
ValueError already raised for timestamp heuristics.

Fixes spotify#489

Signed-off-by: Mike German <mike@stepsventures.com>
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.

normalize_midi_messages() silently drops malformed messages instead of raising an error

1 participant