Skip to content

fix: handle missing audio output config - #453

Open
snvtac wants to merge 1 commit into
Kopuz-org:masterfrom
snvtac:snvtac/447-kopuz-crashes-on-start
Open

fix: handle missing audio output config#453
snvtac wants to merge 1 commit into
Kopuz-org:masterfrom
snvtac:snvtac/447-kopuz-crashes-on-start

Conversation

@snvtac

@snvtac snvtac commented Jun 23, 2026

Copy link
Copy Markdown

Summary

  • Handle missing default audio output devices/configs without panicking during player startup.
  • Keep the player in an unavailable state and return a playback error before spawning decoder work when audio output initialization failed.
  • Surface local playback failures through the existing playback error banner, and render that banner for Local library playback as well as YouTube Music.

Testing

  • rustfmt --check --edition 2024 crates/player/src/player.rs crates/hooks/src/use_player_controller.rs crates/kopuz/src/main.rs
  • git diff --check
  • cargo check

Fixes #447

Summary by CodeRabbit

  • Bug Fixes
    • Playback errors from local files now display with error messages instead of silently failing.
    • App gracefully handles unavailable audio devices instead of crashing.
    • Improved error visibility for both local and streaming playback issues.

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Fixes a startup crash when no audio output device is available. Player now returns a recoverable error instead of panicking when ALSA or another output device is unavailable. Local playback failures propagate to the playback_error signal, and the UI error banner now displays for Local source in addition to YouTube Music.

Changes

Audio Output Error Handling and UI Display

Layer / File(s) Summary
Player struct: unavailable state and audio output guard
crates/player/src/player.rs
Player._device becomes Option<cpal::Device> and audio_output_error: Option<String> is added. New helpers (fallback_stream_config, unavailable, ensure_audio_output) replace expect(...) panics with Err-returning control flow in new(). play() and crossfade_to() each gain an ensure_audio_output()? guard at their entry points.
Error propagation to signal and UI display guard
crates/hooks/src/use_player_controller.rs, crates/kopuz/src/main.rs
On local playback Err(e), the controller now sets playback_error to Some("Playback failed:\n{e}"). The UI banner condition is expanded from YouTube-Music-only to also trigger for Local active-source playback.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • temidaradev

Poem

🐇 No more crashes when the speakers sleep,
The player now gracefully weeps.
An error message, soft and clear,
Instead of panic, just "device not here."
Hop along, the music can wait! 🎵

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main fix: handling missing audio output configuration, which is the core issue resolved in this PR.
Linked Issues check ✅ Passed The PR directly addresses issue #447 by converting a panic on missing audio output config into graceful error handling that allows the application to continue running.
Out of Scope Changes check ✅ Passed All changes are directly related to handling missing audio output and surfacing playback errors, with no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/hooks/src/use_player_controller.rs`:
- Around line 1388-1389: The server and YouTube playback error handling in the
async branch lacks the same error propagation that was fixed for local playback.
In the error handling block around line 805 where errors from
player.write().play or player.write().crossfade_to are caught in the if let
Err(e) = result pattern, the code currently only logs and returns without
setting self.playback_error. Apply the same error visibility fix used for local
playback by setting self.playback_error with the error details in the server/YT
error branch, using the same format:
self.playback_error.set(Some(format!("Playback failed:\n{e}"))) to ensure server
and YouTube playback failures are user-visible.

In `@crates/player/src/player.rs`:
- Around line 256-272: The Player constructor in the new method currently
handles missing device and missing output config gracefully by returning
Self::unavailable, but downstream operations like build_output_stream and play
calls are not protected with error handling, causing panics on audio backend
failures. Wrap the stream building and playback starting logic in error handling
to catch any failures that occur after device and config initialization, and
return Self::unavailable with an appropriate error message for these cases as
well, ensuring all initialization failures are treated as recoverable rather
than causing panics.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b8a8a4e4-f680-4f1d-b329-49213cf85d8f

📥 Commits

Reviewing files that changed from the base of the PR and between c6758b4 and 253fd60.

📒 Files selected for processing (3)
  • crates/hooks/src/use_player_controller.rs
  • crates/kopuz/src/main.rs
  • crates/player/src/player.rs

Comment thread crates/hooks/src/use_player_controller.rs
Comment thread crates/player/src/player.rs
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.

[Bug]: Kopuz crashes on start

1 participant