Skip to content

Commit 8eee1a4

Browse files
Fix panic hook to handle audio backend errors and improve error messaging (#184)
This pull request makes targeted improvements to error handling and code clarity in the audio backend and streaming player logic. The most notable changes are: **Audio Backend Panic Handling:** * The panic hook now recognizes panics originating from both `audio_backend/portaudio.rs` and `audio_backend/rodio.rs`, improving detection and messaging for recoverable audio backend errors. **Streaming Player Logic:** * Refactored the check for the current streaming player in `disconnect_streaming_player` to use the `?` operator for conciseness and readability.
2 parents 89d1216 + 858b2b3 commit 8eee1a4

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/main.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -737,12 +737,15 @@ fn setup_logging() -> anyhow::Result<()> {
737737
fn install_panic_hook() {
738738
let default_hook = panic::take_hook();
739739
panic::set_hook(Box::new(move |info| {
740-
let is_portaudio_panic = info
740+
let is_audio_backend_panic = info
741741
.location()
742-
.map(|location| location.file().contains("audio_backend/portaudio.rs"))
742+
.map(|location| {
743+
let file = location.file();
744+
file.contains("audio_backend/portaudio.rs") || file.contains("audio_backend/rodio.rs")
745+
})
743746
.unwrap_or(false);
744747

745-
if is_portaudio_panic {
748+
if is_audio_backend_panic {
746749
eprintln!(
747750
"Recoverable audio backend panic detected. Playback may pause while the output device changes."
748751
);
@@ -2084,9 +2087,7 @@ async fn disconnect_streaming_player(
20842087
status_message: &str,
20852088
) -> Option<StreamingRecoveryRequest> {
20862089
let mut app_lock = app.lock().await;
2087-
let Some(current_player) = app_lock.streaming_player.as_ref() else {
2088-
return None;
2089-
};
2090+
let current_player = app_lock.streaming_player.as_ref()?;
20902091
if !Arc::ptr_eq(current_player, player) {
20912092
return None;
20922093
}

0 commit comments

Comments
 (0)