Skip to main content

join_panic_to_err

Function join_panic_to_err 

Source
pub fn join_panic_to_err<T>(join_result: Result<T>, label: &str) -> Result<T>
Expand description

Translate a thread::JoinHandle::join result’s panic payload into an anyhow::Error tagged with label. The two common panic payload shapes (&'static str / String) are downcast so the surfaced message is readable rather than the opaque Any placeholder.

Accepts Result<T, Box<dyn Any + Send>> rather than the handle itself so a single helper covers both std::thread::JoinHandle and std::thread::ScopedJoinHandle — both expose .join() returning the same Result shape.

Use when the worker returns T and the caller wants Result<T> so a panic doesn’t propagate as a silently-lost result. For workers that already return Result<T, anyhow::Error>, prefer run_parallel_chunks which bakes this in.