-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't encourage people to ignore threading errors in the docs #44962
Conversation
r? @sfackler (rust_highfive has picked a reviewer for you, use r? to override) |
src/libstd/thread/mod.rs
Outdated
@@ -1192,7 +1194,7 @@ impl<T> JoinInner<T> { | |||
/// }); | |||
/// }); | |||
/// | |||
/// let _ = original_thread.join(); | |||
/// original_thread.join().expect("Unable to join thread"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Join will return an error if the other thread panicked, so this error message may not be the most accurate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it then correct to say that there two failure cases that should be discussed in each case?
- The thread panicked.
- We couldn't
join
(whatever underlying error).
The existing docs for JoinHandle::join
say:
join_handle.join().expect("Couldn't join on the associated thread");
Would you like to see both of the above cases mentioned in every expect? Just in the example for JoinHandle::join
and hope people read it? Something else?
I always regret adding unwrap
to examples because that teaches people to not have useful tracer messages, but saying nothing useful avoids saying something wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would think the JoinHandle docs should change as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would think the JoinHandle docs should change as well.
To be clear, you'd like all the examples to have something like this?
.join().expect("Unable to join thread or thread panicked")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potentially, though the contexts in which the error was due to a join error are really limited.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is personally why I use unwrap
over expect
; it's tough to get a good message.
@sfackler , if you could be more concrete here, that'd be great. I'm happy with whatever, but right now, it's unclear what exactly @shepmaster needs to do for this to land.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is personally why I use
unwrap
overexpect
; it's tough to get a good message.
Wait what?! 😨 It's always better to have a message than just nothing!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shepmaster Docs indicate that the only error that .join() can return is if the thread has panicked
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bluss good point; checking the implementation seems to bear that out:
impl<T> JoinInner<T> {
fn join(&mut self) -> Result<T> {
self.native.take().unwrap().join();
unsafe {
(*self.packet.0.get()).take().unwrap()
}
}
}
The actual join has no potential Result
. Based on that, it seems that the correct course of action is that the messages should say something akin to expect("the thread being joined has panicked")
.
@rust-lang/docs |
I think it's all good except for the issue you pointed at. Once done, it's all good for me. |
0b4412c
to
928013b
Compare
@bors: r+ rollup thanks! |
📌 Commit 928013b has been approved by |
Sorry @steveklabnik, I just saw a lint so I'll r- for now. ;) @bors: r- |
@@ -485,15 +485,17 @@ impl Builder { | |||
/// let (tx, rx) = channel(); | |||
/// | |||
/// let sender = thread::spawn(move || { | |||
/// let _ = tx.send("Hello, thread".to_owned()); | |||
/// tx.send("Hello, thread".to_owned()) | |||
/// .expect("Unable to send on channel"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalid indent, should be:
tx.send("Hello, thread".to_owned())
.expect("Unable to send on channel");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalid indent
Huh. Rustfmt is what indented it this way. Where is this style documented so I can check it before submitting future PRs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rustfmt is really bad... Well, whatever, please align the methods' calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this style documented so I can check it before submitting future PRs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No clue. It's how it's done in the rest of rustc source code. Sorry but I have no idea if there is such a document...
928013b
to
37724f8
Compare
💡 This pull request was already approved, no need to approve it again.
|
📌 Commit 37724f8 has been approved by |
37724f8
to
b5b7666
Compare
@bors: r+ This is in fact standard style, which |
📌 Commit b5b7666 has been approved by |
My bad, thought it was the standard style. |
…eklabnik Don't encourage people to ignore threading errors in the docs
No description provided.