[pbs-devel] [PATCH proxmox-backup 1/1] backup-proxy and parallel_handler: Improved errors when panics occur and the panic message is a formatted (not static) string. This worked already for &str literals, but not for Strings.

Gabriel Goller g.goller at proxmox.com
Tue Jan 21 11:56:04 CET 2025


On 21.01.2025 10:36, Laurențiu Leahu-Vlăducu wrote:
>diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs
>index ce1be1c0..a7dab4ac 100644
>--- a/src/bin/proxmox-backup-proxy.rs
>+++ b/src/bin/proxmox-backup-proxy.rs
>@@ -424,7 +424,10 @@ async fn run_task_scheduler() {
>         match schedule_tasks().catch_unwind().await {
>             Err(panic) => match panic.downcast::<&str>() {
>                 Ok(msg) => eprintln!("task scheduler panic: {msg}"),
>-                Err(_) => eprintln!("task scheduler panic - unknown type"),
>+                Err(panic) => match panic.downcast::<String>() {
>+                    Ok(msg) => eprintln!("task scheduler panic: {msg}"),
>+                    Err(_) => eprintln!("task scheduler panic - cannot show error message due to unknown error type")

AFAIK this gets called after the logging init, so we can use
tracing::error for the log messages here.

>+                }
>             },
>             Ok(Err(err)) => eprintln!("task scheduler failed - {err:?}"),
>             Ok(Ok(_)) => {}
>diff --git a/src/tools/parallel_handler.rs b/src/tools/parallel_handler.rs
>index 17f70179..429a1f8b 100644
>--- a/src/tools/parallel_handler.rs
>+++ b/src/tools/parallel_handler.rs
>@@ -140,7 +140,13 @@ impl<I: Send + 'static> ParallelHandler<I> {
>                         "thread {} ({}) panicked: {}",
>                         self.name, i, panic_msg
>                     )),
>-                    Err(_) => msg_list.push(format!("thread {} ({}) panicked", self.name, i)),
>+                    Err(panic) => match panic.downcast::<String>() {
>+                        Ok(panic_msg) => msg_list.push(format!(
>+                            "thread {} ({}) panicked: {}",
>+                                self.name, i, panic_msg
>+                        )),
>+                        Err(_) => msg_list.push(format!("thread {} ({}) panicked", self.name, i))

A few variables can be be inlined here.

The downcast part looks ok to me.
Please keep the commit message title under 72 characters.

Thanks!




More information about the pbs-devel mailing list