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

Remove usages of unwrap() in non-test code #238

Open
edmorley opened this issue Nov 19, 2023 · 0 comments
Open

Remove usages of unwrap() in non-test code #238

edmorley opened this issue Nov 19, 2023 · 0 comments

Comments

@edmorley
Copy link
Member

We should not use .unwrap() outside of tests. At the very least, failure cases should use .expect() if they are something that could never happen in practice.

A lint to catch cases of this is about to be enabled. It found the following:

warning: used `unwrap()` on a `Result` value
  --> commons/src/output/background_timer.rs:40:22
   |
40 |         let mut io = arc_io.lock().unwrap();
   |                      ^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: if this value is an `Err`, it will panic
   = help: consider using `expect()` to provide a better panic message
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used
   = note: requested on the command line with `-W clippy::unwrap-used`

warning: `commons` (lib) generated 1 warning
warning: used `unwrap()` on a `Result` value
  --> commons/bin/print_style_guide.rs:66:9
   |
66 |         command.stream_output(stream.io(), stream.io()).unwrap();
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: if this value is an `Err`, it will panic
   = help: consider using `expect()` to provide a better panic message
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used
   = note: requested on the command line with `-W clippy::unwrap-used`

warning: used `unwrap()` on a `Result` value
   --> commons/bin/print_style_guide.rs:103:13
    |
103 | /             Command::new("bash")
104 | |                 .args(["-c", "ps aux | grep cargo"])
105 | |                 .stream_output(stream.io(), stream.io())
106 | |                 .unwrap()
    | |_________________________^
    |
    = note: if this value is an `Err`, it will panic
    = help: consider using `expect()` to provide a better panic message
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used

warning: used `unwrap()` on an `Option` value
   --> commons/bin/print_style_guide.rs:116:25
    |
116 |         let cmd_error = Command::new("iDoNotExist").named_output().err().unwrap();
    |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: if this value is `None`, it will panic
    = help: consider using `expect()` to provide a better panic message
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant