From 54011e7ff1e8532d36fbc755d11456048d90615d Mon Sep 17 00:00:00 2001 From: Tarasov Aleksandr <55220741+arabianq@users.noreply.github.com> Date: Mon, 1 Jun 2026 22:48:08 +0300 Subject: [PATCH] fix(daemon): Replace unwrap with safe Option handling in audio_player (#125) The `play` method in `src/types/audio_player.rs` previously used `.unwrap()` directly on `self.stream_handle.as_ref()`. This posed a security/stability risk where if `stream_handle` was uninitialized or became `None` unexpectedly despite the prior `ensure_stream()` call, it would cause the thread to panic and potentially crash the application. This commit replaces the `.unwrap()` call with `.ok_or_else` to safely handle the `None` case, returning an `anyhow` error instead of panicking, adhering to the project's no-panic policy. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- src/types/audio_player.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/types/audio_player.rs b/src/types/audio_player.rs index 238cd7b..0f74193 100644 --- a/src/types/audio_player.rs +++ b/src/types/audio_player.rs @@ -349,7 +349,11 @@ impl AudioPlayer { let duration = source.total_duration().map(|d| d.as_secs_f32()); - let mixer = self.stream_handle.as_ref().unwrap().mixer(); + let mixer = self + .stream_handle + .as_ref() + .ok_or_else(|| anyhow::anyhow!("stream_handle is unexpectedly missing"))? + .mixer(); let sink = Player::connect_new(mixer); sink.set_volume(self.volume); // Default volume is 1.0 * master sink.append(source);