Skip to content

fix: raise TypeError for unrecognised messages in normalize_midi_messages - #490

Open
m-zandi wants to merge 2 commits into
spotify:masterfrom
m-zandi:fix/normalize-midi-messages-silent-drop
Open

fix: raise TypeError for unrecognised messages in normalize_midi_messages#490
m-zandi wants to merge 2 commits into
spotify:masterfrom
m-zandi:fix/normalize-midi-messages-silent-drop

Conversation

@m-zandi

@m-zandi m-zandi commented Jun 10, 2026

Copy link
Copy Markdown

What this PR does

Fixes the silent data-loss bug in normalize_midi_messages() where
unrecognised MIDI messages (wrong tuple length, bare bytes, unknown type,
etc.) were silently dropped from the output list.

Changes

  • pedalboard/midi_utils.py — Added else branch that raises TypeError
    with the index and repr of the offending element, so callers get an
    immediate, actionable error instead of a shorter-than-expected list.
  • tests/test_midi_utils.py — Added parametrized regression tests covering
    1-tuples, 3-tuples, bare bytes, bare integers, and None.

Closes

Closes #489

How to test

pytest tests/test_midi_utils.py -v

All new tests should pass. The existing test_mido_normalization test is
unaffected.

Before / After

Before:

result = normalize_midi_messages([(bytes([0x90, 60, 64]),)])
print(result)  # [] — silently dropped, no error

After:

result = normalize_midi_messages([(bytes([0x90, 60, 64]),)])
# TypeError: Could not interpret MIDI message at index 0: (b'\x90<@',).
# Expected an object with 'bytes()' and 'time' attributes (e.g. mido.Message),
# or a 2-element tuple/list of (message_bytes, timestamp_seconds).

m-zandi added 2 commits June 10, 2026 03:33
…ages

Previously, any message that did not match the expected formats
(mido-style object or 2-tuple) was silently dropped. This caused
silent data loss that was impossible to detect without manually
comparing input and output lengths.

The fix adds an `else` branch that raises TypeError immediately,
including the index and repr of the offending element so callers
can identify and correct their data.

Closes spotify#489
Covers spotify#489 — ensures malformed messages raise TypeError rather than being silently discarded.
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