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

Avoid using unwrap #184

Merged
merged 2 commits into from Mar 3, 2021
Merged

Avoid using unwrap #184

merged 2 commits into from Mar 3, 2021

Conversation

jack-signal
Copy link
Contributor

@jack-signal jack-signal commented Feb 5, 2021

If we must assert that a value is Ok/Some use expect 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)

@jack-signal jack-signal force-pushed the jack/no-unwrap branch 2 times, most recently from b2d8b08 to 30066ec Compare February 5, 2021 17:47
rust/protocol/src/fingerprint.rs Show resolved Hide resolved

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

danburkert/prost#154 😭

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -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>
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@jack-signal jack-signal force-pushed the jack/no-unwrap branch 2 times, most recently from 68f5945 to 84c7a58 Compare February 5, 2021 21:29
@jack-signal jack-signal force-pushed the jack/no-unwrap branch 2 times, most recently from b77a689 to 1346cb6 Compare March 3, 2021 17:03
@jack-signal
Copy link
Contributor Author

@jrose-signal ready for another look

Copy link
Contributor

@jrose-signal jrose-signal left a 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.

rust/bridge/jni/src/lib.rs Show resolved Hide resolved
Remove some unwrap from poksho and futures crates
@jack-signal jack-signal merged commit 050342b into master Mar 3, 2021
@jack-signal jack-signal deleted the jack/no-unwrap branch March 3, 2021 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants