Skip to content
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

Merged
merged 1 commit into from
Oct 10, 2017

Conversation

shepmaster
Copy link
Member

No description provided.

@rust-highfive
Copy link
Collaborator

r? @sfackler

(rust_highfive has picked a reviewer for you, use r? to override)

@shepmaster shepmaster added C-enhancement Category: An issue proposing an enhancement or a PR with one. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools labels Oct 1, 2017
@@ -1192,7 +1194,7 @@ impl<T> JoinInner<T> {
/// });
/// });
///
/// let _ = original_thread.join();
/// original_thread.join().expect("Unable to join thread");
Copy link
Member

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.

Copy link
Member Author

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?

  1. The thread panicked.
  2. 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.

Copy link
Member

@sfackler sfackler Oct 1, 2017

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.

Copy link
Member Author

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")

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

Wait what?! 😨 It's always better to have a message than just nothing!

Copy link
Member

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

Copy link
Member Author

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").

@sfackler
Copy link
Member

sfackler commented Oct 1, 2017

@rust-lang/docs

@GuillaumeGomez
Copy link
Member

I think it's all good except for the issue you pointed at. Once done, it's all good for me.

@steveklabnik
Copy link
Member

@bors: r+ rollup

thanks!

@bors
Copy link
Contributor

bors commented Oct 5, 2017

📌 Commit 928013b has been approved by steveklabnik

@GuillaumeGomez
Copy link
Member

GuillaumeGomez commented Oct 6, 2017

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");
Copy link
Member

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");

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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...

@bors
Copy link
Contributor

bors commented Oct 8, 2017

💡 This pull request was already approved, no need to approve it again.

@bors
Copy link
Contributor

bors commented Oct 8, 2017

📌 Commit 37724f8 has been approved by steveklabnik

@rust-lang rust-lang deleted a comment from bors Oct 8, 2017
@steveklabnik
Copy link
Member

@bors: r+

This is in fact standard style, which rustc has not yet fully adopted, but will. We want to show standard style in the docs. I can understand if you don't like that style, @GuillaumeGomez , as there's some parts I'm not psyched about either, but sticking with the standard is worth arguing over quibbles like these.

@bors
Copy link
Contributor

bors commented Oct 8, 2017

📌 Commit b5b7666 has been approved by steveklabnik

@GuillaumeGomez
Copy link
Member

My bad, thought it was the standard style.

kennytm added a commit to kennytm/rust that referenced this pull request Oct 9, 2017
…eklabnik

Don't encourage people to ignore threading errors in the docs
bors added a commit that referenced this pull request Oct 10, 2017
Rollup of 9 pull requests

- Successful merges: #44962, #45051, #45091, #45106, #45117, #45118, #45120, #45125, #45136
- Failed merges:
@bors bors merged commit b5b7666 into rust-lang:master Oct 10, 2017
@shepmaster shepmaster deleted the no-ignore-result branch October 10, 2017 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants