-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Replace unwrap calls in examples by expect #51668
Conversation
I think it's OK to use |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@euclio: Beyond than just use |
Right, I understand that we should be discouraging The reason we want to discourage My second point is that if you're writing |
Yup, agreed with Andy here.
… On Jun 21, 2018, at 9:18 AM, Andy Russell ***@***.***> wrote:
Right, I understand that we should be discouraging unwrap. But, I think that unwrap has its uses, and a blanket ban in std documentation seems too heavy-handed to me.
The reason we want to discourage unwrap is twofold. First, you don't want to unwrap when you should be propagating or handling the error instead. std documentation already does this throughout, so it's not relevant to this PR. Second, unwrap doesn't provide any information about why we thought it was OK to unwrap in the case of failure. That's why expect exists: so we can display that reasoning. Using expect with a message like expect("func() failed") isn't much better than unwrap, because the only information it provides is that the method failed, which is what unwrap gives us. Instead, expect should contain the reasoning behind the expect, like I said above.
My second point is that if you're writing expect messages like that, then an expression like CString::new("foo").expect("0 byte found in literal") is redundant: obviously a 0-byte does not occur in the literal. At that point, the expect is just line noise, and I'd prefer unwrap.
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
We agree on the fact that messages I wrote should be improved. My point was that, in any case, docs shouldn't provide examples with |
Ping from triage, @GuillaumeGomez: what's the status of this? |
Need to update. |
☔ The latest upstream changes (presumably #52486) made this pull request unmergeable. Please resolve the merge conflicts. |
Ping from triage @GuillaumeGomez! It's been a while since we heard from you, will you have time to work on this again? |
Yep, don't know when but yep. |
Frendly weekly ping from triage @GuillaumeGomez! |
I'll update it some day! :D |
Triage: @GuillaumeGomez Have you been able to get back to this? |
Soon, it'll take a bit of time. |
4a8260a
to
a3cc2a1
Compare
a3cc2a1
to
a747842
Compare
So, made few improvements on some wordings. However:
I don't agree with that statement for example:
Yes but it is more clear (and you can add additional information). Again, this is all about giving good habits to users. Even a message like "fuck it" would be super useful to find where the error comes from (unless you have a few of them of course). In any case, I tried to improve messages a bit but I don't know how I could make them better at this point so any suggestion is very welcome if you think they could be improved. :) |
Again, this is all about giving good habits to users. Even a message like "fuck it" would be super useful to find where the error comes from (unless you have a few of them of course).
This is what the stack trace provides, no? Also, I would argue that using `expect` with a uninformative message is actually a bad habit.
…On Sun, Aug 12, 2018, 3:04 AM Guillaume Gomez ***@***.***> wrote:
So, made few improvements on some wordings. However:
Right, I understand that we should be discouraging unwrap. But, I think
that unwrap has its uses, and a blanket ban in std documentation seems too
heavy-handed to me.
I don't agree with that statement for example: expect does exactly the
same but in addition provides a message which is *information*. The more
information the better, even more on a code written in a language which
intends to have a reputation of never crashing (wether it's true or not).
Using expect with a message like expect("func() failed") isn't much better
than unwrap, because the only information it provides is that the method
failed, which is what unwrap gives us
Yes but it is more clear (and you can add additional information).
Again, this is all about giving good habits to users. Even a message like
"fuck it" would be super useful to find where the error comes from (unless
you have a few of them of course).
In any case, I tried to improve messages a bit but I don't know how I
could make them better at this point so any suggestion is very welcome if
you think they could be improved. :)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#51668 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABTxFrGjK9I8UKcoA5lQFdU0s9SDoih5ks5uPxyxgaJpZM4UwF2R>
.
|
Yes and no. Stack trace only indicates functions most of the time (it's already a good start but still lacking).
I think this is more a question of opinion in here. I want an error message to be informative whereas I want a panic message to be easy to be grepped so I can fix it because a panic should never happen on the opposite of an error message. |
Ping from triage @GuillaumeGomez! It's been a while since we heard from you, will you have time to work on this again? |
Debate is still going on. :) |
Ping from triage @GuillaumeGomez / @steveklabnik. What is the status of this PR? Is this blocked on some external issue? |
I don't know actually. The debate is "should expect sentences be more useful than easy to grep" basically. |
I think so. From the first comment:
If this were only the ones where things can fail, we could merge, it's the others that are controversial. |
@steveklabnik Ok, I'll make a first PR for the mergeable one and open another one with the rest. |
Ping from triage! I'm marking this as "blocked" on the individual, smaller PRs. |
…eklabnik Replace unwrap calls in example by expect Part of rust-lang#51668. r? @steveklabnik
☔ The latest upstream changes (presumably #54168) made this pull request unmergeable. Please resolve the merge conflicts. |
Ping from triage @GuillaumeGomez what's the update on this? |
This PR is a bit behind. I need to cut it into small pieces to be merged separately. |
@GuillaumeGomez it's been a few months; since it's gonna get cut into pieces anyway, I'm going to close this to clear out my queue. thanks. |
Sure, completely forgot about it! |
Because no one should use
unwrap
!r? @steveklabnik