heroku / heroku/buildpacks-ruby

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

Open
#238 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
30
Forks
7
Avg merge
1d 17h
Merged PRs (30d)
5

Description

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
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.