mirror of
https://git.proxmox.com/git/proxmox
synced 2025-04-28 17:08:47 +00:00
rest-server: Improved panic errors with formatted strings
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:
b605c65b6e/library/std/src/panicking.rs (L777)
Signed-off-by: Laurențiu Leahu-Vlăducu <l.leahu-vladucu@proxmox.com>
This commit is contained in:
parent
f639695c87
commit
922c605d69
@ -980,9 +980,14 @@ impl WorkerTask {
|
||||
|
||||
let result = match std::panic::catch_unwind(move || f(worker1)) {
|
||||
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) => {
|
||||
if let Some(panic_msg) = panic.downcast_ref::<&str>() {
|
||||
Err(format_err!("worker panicked: {panic_msg}"))
|
||||
} else if let Some(panic_msg) = panic.downcast_ref::<String>() {
|
||||
Err(format_err!("worker panicked: {panic_msg}"))
|
||||
} else {
|
||||
Err(format_err!("worker panicked: cannot show error message due to unknown error type."))
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user