Skip to content

Fix TypeError when channel/acquisition metadata contains None values#169

Merged
cbrnr merged 2 commits intoxdf-modules:mainfrom
sappelhoff:fix-none-channel-metadata
Mar 31, 2026
Merged

Fix TypeError when channel/acquisition metadata contains None values#169
cbrnr merged 2 commits intoxdf-modules:mainfrom
sappelhoff:fix-none-channel-metadata

Conversation

@sappelhoff
Copy link
Copy Markdown
Contributor

@sappelhoff sappelhoff commented Mar 31, 2026

Disclaimer: I created this PR and the content using Claude.


Summary

playback_lsl.py crashes with a TypeError when an XDF file contains channel or acquisition metadata fields that are present but have None values:

TypeError: descriptor 'encode' for 'str' objects doesn't apply to a 'NoneType' object

This happens in pylsl's append_child_value, which calls str.encode() on the value passed to it.

Fix

  • Skip metadata fields whose value is None (guard added to both the acquisition and channel loops)
  • Wrap values in str() so non-string scalars (e.g. a numeric precision field) are also handled correctly

Test plan

  • Reproduce with an XDF file that has None channel metadata (e.g. a missing unit field) — previously crashed, now streams successfully
  • Verify that XDF files with fully populated metadata still stream correctly

When an XDF file has channel or acquisition metadata fields present but
with null values, playback_lsl.py would crash with:

    TypeError: descriptor 'encode' for 'str' objects doesn't apply to a 'NoneType' object

because pylsl's append_child_value calls str.encode() on the value.

Add a None-check before each append_child_value call, and wrap the value
in str() so that non-string scalars (e.g. numeric precision fields) are
also handled safely.
@sappelhoff
Copy link
Copy Markdown
Contributor Author

cc @cbrnr

@cbrnr
Copy link
Copy Markdown
Contributor

cbrnr commented Mar 31, 2026

Thanks! LGTM! Can you add a changelog entry please?

@cbrnr cbrnr merged commit cf26463 into xdf-modules:main Mar 31, 2026
6 checks passed
@cbrnr
Copy link
Copy Markdown
Contributor

cbrnr commented Mar 31, 2026

Thanks @sappelhoff!

@sappelhoff sappelhoff deleted the fix-none-channel-metadata branch March 31, 2026 14:31
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