I want to propagate an error from a function called inside a closure inside a call to thread::spawn.
I've tried using a JoinHandle to capture the result of thread::spawn, but I get various errors doing that.
fn start_server(args) -> Result<(), Box<dyn std::error::Error>> { ... thread::spawn(move || { // I want to do this (put a ? after run_server) run_server(args)?; ... } ... }); fn run_server(args) -> Result<(), std::io::Error> { ... } I get this message
| run_server(args)?; | ^^^^^^^^^^^^^^^^^ cannot use the `?` operator in a function that returns `()` | = help: the trait `std::ops::Try` is not implemented for `()` = note: required by `std::ops::Try::from_error`
...afterrun_server(args)?. That is, you didn't post enough details to answer why the closure returns().