buildpacks-ruby icon indicating copy to clipboard operation
buildpacks-ruby copied to clipboard

Remove usages of `unwrap()` in non-test code

Open edmorley opened this issue 2 years ago • 0 comments

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

edmorley avatar Nov 19 '23 14:11 edmorley