[pbs-devel] [PATCH proxmox 1/1] rest-server: 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.

Laurențiu Leahu-Vlăducu l.leahu-vladucu at proxmox.com
Tue Jan 21 10:36:12 CET 2025


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 at proxmox.com>
---
 proxmox-rest-server/src/worker_task.rs | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/proxmox-rest-server/src/worker_task.rs b/proxmox-rest-server/src/worker_task.rs
index beec691e..45ee4e34 100644
--- a/proxmox-rest-server/src/worker_task.rs
+++ b/proxmox-rest-server/src/worker_task.rs
@@ -982,7 +982,10 @@ impl WorkerTask {
                         Ok(r) => r,
                         Err(panic) => match panic.downcast::<&str>() {
                             Ok(panic_msg) => Err(format_err!("worker panicked: {}", panic_msg)),
-                            Err(_) => Err(format_err!("worker panicked: unknown type.")),
+                            Err(panic) => match panic.downcast::<String>() {
+                                Ok(panic_msg) => Err(format_err!("worker panicked: {}", panic_msg)),
+                                Err(_) => Err(format_err!("worker panicked: cannot show error message due to unknown error type."))
+                            },
                         },
                     };
 
-- 
2.39.5





More information about the pbs-devel mailing list