Skip to content

Commit 9eba0be

Browse files
balloobclaude
andauthored
Show specific reason when hardware volume is unavailable (#152)
## Summary - Split the generic `except (ImportError, OSError)` in `hardware_volume.py` into separate handlers, each capturing a descriptive `UNAVAILABLE_REASON` - The CLI error message now tells the user exactly what's wrong: missing Python package (`pulsectl-asyncio`) vs missing system library (`libpulse0`) vs non-Linux platform - Previously, the error always said "Install pulsectl-asyncio" even when the package was installed but the system library was missing Closes #151 ## Test plan - [ ] On Linux without `libpulse0`: verify error mentions `sudo apt-get install libpulse0` - [ ] On Linux without `pulsectl-asyncio`: verify error mentions `pip install pulsectl-asyncio` - [ ] On non-Linux: verify error mentions "only supported on Linux" - [ ] On Linux with everything installed: verify hardware volume works normally 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ae631df commit 9eba0be

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

‎sendspin/cli.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from typing import TYPE_CHECKING
1515

1616
from sendspin.hardware_volume import AVAILABLE as HW_VOLUME_AVAILABLE
17+
from sendspin.hardware_volume import UNAVAILABLE_REASON as HW_VOLUME_UNAVAILABLE_REASON
1718
from sendspin.hardware_volume import async_check_available as hw_volume_check_available
1819
from sendspin.settings import ClientSettings, get_client_settings, get_serve_settings
1920

@@ -591,8 +592,8 @@ async def _run_client_mode(args: argparse.Namespace) -> int:
591592
args.hardware_volume = is_daemon and HW_VOLUME_AVAILABLE
592593
if args.hardware_volume and not HW_VOLUME_AVAILABLE:
593594
raise CLIError(
594-
"Hardware volume control is not available on this system. "
595-
"Install pulsectl-asyncio on Linux, or use --hardware-volume false."
595+
f"Hardware volume control is not available on this system. "
596+
f"{HW_VOLUME_UNAVAILABLE_REASON or 'Use --hardware-volume false to disable.'}"
596597
)
597598
if args.hook_start is None:
598599
args.hook_start = settings.hook_start

‎sendspin/hardware_volume.py‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,24 @@
1010
from typing import Any
1111

1212
AVAILABLE = False
13-
if sys.platform.startswith("linux"):
13+
UNAVAILABLE_REASON: str | None = None
14+
if not sys.platform.startswith("linux"):
15+
UNAVAILABLE_REASON = "Hardware volume control is only supported on Linux."
16+
else:
1417
try:
1518
import pulsectl_asyncio
1619

1720
AVAILABLE = True
18-
except (ImportError, OSError):
19-
pass
21+
except ImportError:
22+
UNAVAILABLE_REASON = (
23+
"pulsectl-asyncio package is not installed. "
24+
"Install it with: pip install pulsectl-asyncio"
25+
)
26+
except OSError as _exc:
27+
UNAVAILABLE_REASON = (
28+
f"PulseAudio system library failed to load: {_exc}. "
29+
"Install it with: sudo apt-get install libpulse0"
30+
)
2031

2132
logger = logging.getLogger(__name__)
2233

0 commit comments

Comments
 (0)