Skip to content

Commit

Permalink
Rollup merge of rust-lang#57833 - jethrogb:jb/thread-spawn-unwrap, r=…
Browse files Browse the repository at this point in the history
…alexcrichton

Print a slightly clearer message when failing to launch a thread

As discussed in rust-lang#46345, the `io::Error` you get when a thread fails to launch is of type `io::ErrorKind::WouldBlock`. This is super uninformative when an arbitrary `thread::spawn` fails somewhere in your code:

```
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 11,
kind: WouldBlock, message: "operation would block" }', src/libcore/result.rs:997:5
```

This PR improves the situation a little bit by using `expect` instead of `unwrap`. I don't consider this a complete fix for rust-lang#46345 though.
  • Loading branch information
Centril authored Jan 28, 2019
2 parents 76dbfdd + 2ec0e85 commit 42dae3a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/libstd/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ impl Builder {
pub fn spawn<F, T>(f: F) -> JoinHandle<T> where
F: FnOnce() -> T, F: Send + 'static, T: Send + 'static
{
Builder::new().spawn(f).unwrap()
Builder::new().spawn(f).expect("failed to spawn thread")
}

/// Gets a handle to the thread that invokes it.
Expand Down

0 comments on commit 42dae3a

Please sign in to comment.