Skip to content

fix(audio): treat ValueError from format probing as unsupported (raw ALSA devices) - #286

Merged
OnFreund merged 1 commit into
Sendspin:mainfrom
kiwipaulrob:fix/alsa-format-detect-valueerror
Oct 6, 2026
Merged

OnFreund merged 1 commit into
Sendspin:mainfrom
kiwipaulrob:fix/alsa-format-detect-valueerror

Conversation

@kiwipaulrob

Copy link
Copy Markdown
Contributor

Problem

--audio-device accepts raw ALSA names (e.g. hw:CARD=sndrpihifiberry,DEV=0, dmix, plug). resolve_audio_device() handles those through _try_alsa_device(), which — since #224 — treats PortAudio's ValueError as a lookup miss and validates the name against aplay -L.

The format-detection step that runs afterwards was missed: _check_format() only catches sounddevice.PortAudioError, while PortAudio raises ValueError for the very same unrecognised names. A device resolved this way has index=None and only an alsa_device_name, so device.device_id is that raw name; check_output_settings() therefore raises ValueError, it escapes _check_format(), and it propagates out of detect_supported_audio_formats() — the client fails at startup before it ever reaches the server.

That is the failure reported in #262 (and the same class as #251): a device listed by sendspin audio-devices list still cannot be used.

Fix

Catch ValueError alongside PortAudioError in _check_format() and report the format as unsupported, exactly as _try_alsa_device() already does on the resolution path. detect_supported_audio_formats() then takes its existing "Could not detect supported formats, using safe defaults" branch, so startup proceeds and the real format is negotiated with the server later.

Verification

  • pytest — 149 passed, including 2 new tests in tests/test_audio_devices.py:
    • _check_format() returns False (instead of raising) when check_output_settings raises ValueError;
    • detect_supported_audio_formats() returns non-empty safe defaults for an ALSA-only device.
  • ruff check, ruff format --check, mypy sendspin all clean.

Fixes #262
Refs #251

PortAudio raises ValueError (not PortAudioError) for device names it does
not recognise, e.g. raw ALSA names such as hw:CARD=...,DEV=... .
_check_format() only caught PortAudioError, so detect_supported_audio_formats()
raised at startup for such devices and the documented raw-ALSA --audio-device
form was unusable. Treat it as an unsupported format so the existing
safe-default fallback applies. Mirrors the ValueError handling already added to
_try_alsa_device() in Sendspin#224.
@OnFreund
OnFreund merged commit 2a1dbbe into Sendspin:main Oct 6, 2026
2 checks passed
@maximmaxim345 maximmaxim345 added the bugfix Fixes a bug label Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error: No output device matching

3 participants