public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: "Laurențiu Leahu-Vlăducu" <l.leahu-vladucu@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup v2 1/1] proxy/parallel_handler: Improved panic errors with formatted strings
Date: Tue, 21 Jan 2025 14:11:46 +0100	[thread overview]
Message-ID: <20250121131147.125433-2-l.leahu-vladucu@proxmox.com> (raw)
In-Reply-To: <20250121131147.125433-1-l.leahu-vladucu@proxmox.com>

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.

Downcasting to both &str and String is also done by the Rust Standard
Library in the default panic handler. See:
https://github.com/rust-lang/rust/blob/b605c65b6eb5fa71783f8e26df69975f9f1680ee/library/std/src/panicking.rs#L777

Signed-off-by: Laurențiu Leahu-Vlăducu <l.leahu-vladucu@proxmox.com>
---

Changes since v1:
* use tracing::error instead of eprintln
* inline some variables when formatting

 src/bin/proxmox-backup-proxy.rs |  9 ++++++---
 src/tools/parallel_handler.rs   | 10 +++++-----
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs
index ce1be1c0..21602fdc 100644
--- a/src/bin/proxmox-backup-proxy.rs
+++ b/src/bin/proxmox-backup-proxy.rs
@@ -423,10 +423,13 @@ 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"),
+                Ok(msg) => tracing::error!("task scheduler panic: {msg}"),
+                Err(panic) => match panic.downcast::<String>() {
+                    Ok(msg) => tracing::error!("task scheduler panic: {msg}"),
+                    Err(_) => tracing::error!("task scheduler panic - cannot show error message due to unknown error type")
+                }
             },
-            Ok(Err(err)) => eprintln!("task scheduler failed - {err:?}"),
+            Ok(Err(err)) => tracing::error!("task scheduler failed - {err:?}"),
             Ok(Ok(_)) => {}
         }
     }
diff --git a/src/tools/parallel_handler.rs b/src/tools/parallel_handler.rs
index 17f70179..afa0bc97 100644
--- a/src/tools/parallel_handler.rs
+++ b/src/tools/parallel_handler.rs
@@ -136,11 +136,11 @@ impl<I: Send + 'static> ParallelHandler<I> {
         while let Some(handle) = self.handles.pop() {
             if let Err(panic) = handle.join() {
                 match panic.downcast::<&str>() {
-                    Ok(panic_msg) => msg_list.push(format!(
-                        "thread {} ({}) panicked: {}",
-                        self.name, i, panic_msg
-                    )),
-                    Err(_) => msg_list.push(format!("thread {} ({}) panicked", self.name, i)),
+                    Ok(panic_msg) => msg_list.push(format!("thread {} ({i}) panicked: {panic_msg}", self.name)),
+                    Err(panic) => match panic.downcast::<String>() {
+                        Ok(panic_msg) => msg_list.push(format!("thread {} ({i}) panicked: {panic_msg}", self.name)),
+                        Err(_) => msg_list.push(format!("thread {} ({i}) panicked", self.name))
+                    },
                 }
             }
             i += 1;
-- 
2.39.5



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel

  reply	other threads:[~2025-01-21 13:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-21 13:11 [pbs-devel] [PATCH proxmox/proxmox-backup v2 0/1] " Laurențiu Leahu-Vlăducu
2025-01-21 13:11 ` Laurențiu Leahu-Vlăducu [this message]
2025-01-24  8:42   ` [pbs-devel] [PATCH proxmox-backup v2 1/1] proxy/parallel_handler: " Thomas Lamprecht
2025-01-24 15:30     ` Laurențiu Leahu-Vlăducu
2025-01-21 13:11 ` [pbs-devel] [PATCH proxmox v2 1/1] rest-server: " Laurențiu Leahu-Vlăducu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250121131147.125433-2-l.leahu-vladucu@proxmox.com \
    --to=l.leahu-vladucu@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal