Fix two critical bugs: bluetoothctl EOF handling and record filename directory creation #224
+27
−14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes two critical bugs that prevent core muselsl functionality from working on certain systems.
Bug 1: Bluetoothctl EOF Handling (
muselsl/stream.py)Problem:
muselsl listfails withValueError: Unexpected error when scanningon systems wherebluetoothctlexits cleanly with EOF instead of timing out.Root Cause: The code treated
pexpect.EOFas an error condition, butbluetoothctl scan onmay exit cleanly after starting the scan (which continues at the Bluetooth stack level). Both EOF and TIMEOUT are valid completion conditions.Fix:
pexpect.EOFandpexpect.TIMEOUTas normal scan completionImpact: Enables device discovery on systems where bluetoothctl exits immediately (tested on Debian 12, Python 3.13).
Bug 2: Record Filename Directory Creation (
muselsl/record.py)Problem:
muselsl record -f filename.csvfails withFileNotFoundError: [Errno 2] No such file or directory: ''when using simple filenames without directory paths.Root Cause: When
os.path.dirname('file.csv')returns an empty string, the code attemptsos.makedirs(''), which raises an exception.Fix: Added check to skip directory creation when
dirname()returns empty string (applied to both_save()andrecord_direct()functions).Impact: Allows users to record with simple filenames like
test.csvin the current directory, while preserving existing behavior for paths with directories.Testing
✅ Verified on Debian 12, Python 3.13
✅ Device discovery works with
muselsl list✅ Recording works with simple filenames:
muselsl record -f test.csv✅ Recording works with directory paths:
muselsl record -f data/test.csv✅ No regression in existing functionality
Related Issues
Changes
muselsl/stream.py: Lines 90-106 - Fixed EOF handling in_list_muses_bluetoothctl()muselsl/record.py: Lines 152, 266 - Added empty string check beforeos.makedirs()Both changes are minimal, safe, and maintain backward compatibility.
🤖 Generated with Claude Code