I use error_chain for my error handling.
[dependencies]
error-chain = "0.12.2"
I have no problem when I'm only using a single-thread.
#[macro_use] extern crate error_chain;
error_chain! {}
fn main() -> Result<()> {
crash_burn()
.chain_err(|| "crash_burn() crashed and burned!")?;
Ok(())
}
fn crash_burn() -> Result<()> {
bail!("I'm an error.")
}
However, when trying to return an error from a thread I get a compilation error.
#[macro_use] extern crate error_chain;
error_chain! {}
use std::thread::*;
fn main() -> Result<()> {
let child: JoinHandle<Result<()>> = spawn(move || {
crash_burn()
.chain_err(|| "crash_burn() crashed and burned!")?;
Ok(())
});
let res = child.join()
.chain_err(|| "Child thread panicked! This error did not come from crash_burn().")?;
res // res contains the error from crash_burn()
}
Here is the compilation error.
error[E0599]: no method named `chain_err` found for enum `std::result::Result<std::result::Result<(), Error>, std::boxed::Box<(dyn std::any::Any + std::marker::Send + 'static)>>` in the current scope
--> src/main.rs:13:10
|
13 | .chain_err(|| "Child thread panicked! This error did not come from crash_burn().")?;
| ^^^^^^^^^ method not found in `std::result::Result<std::result::Result<(), Error>, std::boxed::Box<(dyn std::any::Any + std::marker::Send + 'static)>>`
Why is this error not handled automatically?