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
Avoid using unwrap #184
Avoid using unwrap #184
Conversation
b2d8b08
to
30066ec
Compare
|
||
// prost documents the only possible encoding error is if there is insufficient | ||
// space, which is not a problem when it is allowed to encode into a Vec | ||
structure.encode(&mut result).expect("No encoding error"); |
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.
danburkert/prost#154 😭
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.
https://github.com/danburkert/prost/pull/378 stalled since October :(
@@ -625,7 +632,7 @@ mod tests { | |||
use rand::rngs::OsRng; | |||
use rand::{CryptoRng, Rng}; | |||
|
|||
fn create_signal_message<T>(csprng: &mut T) -> SignalMessage | |||
fn create_signal_message<T>(csprng: &mut T) -> Result<SignalMessage> |
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 one doesn't really make sense to me. It may be a helper function for a test, but it actually cannot fail, and immediately panicking is valid. Can you use expect
instead?
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.
Sure I guess. Reasoning was to avoid as many expects
in src
as possible since those need to be audited for panics, and having tests using unwrap/expect makes it harder to find ones that are in the protocol src proper.
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.
Eh, my opinion is that auditing is all well and good, but not at the cost of actual type signatures. I can see how being a test helper puts it on the edge, though.
Another option would be to go back to use unwrap
in tests, since the Clippy warning keeps it out of the src files. Any of these three options are all right with me though.
68f5945
to
84c7a58
Compare
b77a689
to
1346cb6
Compare
1346cb6
to
14060ae
Compare
@jrose-signal ready for another look |
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.
We've added poksho to the repository since the original PR. signal-neon-futures is also a separate crate (rust/bridge/node/futures), so we'll need to apply this there as well.
Remove some unwrap from poksho and futures crates
bae72b7
to
a56874e
Compare
If we must assert that a value is
Ok
/Some
useexpect
with a string explaining why this must be so.Most of the changes here are in the tests, where of course
unwrap
is mostly harmless. But updating there as well makes it easy to grep for any other uses.(This skips
unwrap_or
because those don't panic)