mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-06-19 12:13:32 +00:00
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>
This commit is contained in:
committed by
GitHub
parent
dac9d53cef
commit
54011e7ff1
@@ -349,7 +349,11 @@ impl AudioPlayer {
|
|||||||
|
|
||||||
let duration = source.total_duration().map(|d| d.as_secs_f32());
|
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);
|
let sink = Player::connect_new(mixer);
|
||||||
sink.set_volume(self.volume); // Default volume is 1.0 * master
|
sink.set_volume(self.volume); // Default volume is 1.0 * master
|
||||||
sink.append(source);
|
sink.append(source);
|
||||||
|
|||||||
Reference in New Issue
Block a user