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

package_buildpack() contains an unwrap() in non-test code #710

Closed
edmorley opened this issue Nov 2, 2023 · 1 comment · Fixed by #720
Closed

package_buildpack() contains an unwrap() in non-test code #710

edmorley opened this issue Nov 2, 2023 · 1 comment · Fixed by #720
Assignees
Labels
bug Something isn't working libcnb-test

Comments

@edmorley
Copy link
Member

edmorley commented Nov 2, 2023

#666 introduced an .unwrap() in non-#[cfg(test)] code, here:

fs::create_dir_all(&buildpack_destination_dir).unwrap();

We should never use .unwrap() apart from in tests.

In particular, package_buildpack() already returns a Result, so this failure mode should be converted to another error variant within it.

@edmorley edmorley added bug Something isn't working libcnb-test labels Nov 2, 2023
@edmorley
Copy link
Member Author

edmorley commented Nov 2, 2023

There's a lint we can enable to prevent this in the future:
https://rust-lang.github.io/rust-clippy/master/index.html#/unwrap_used

@edmorley edmorley self-assigned this Nov 2, 2023
edmorley added a commit that referenced this issue Nov 2, 2023
…`panic!` (#711)

The `clippy::unwrap_used` lint prevents usage of `.unwrap()` outside of tests:
https://rust-lang.github.io/rust-clippy/master/index.html#/unwrap_used

The `clippy::panic_in_result_fn` lint prevents usages of `assert!` or
`panic!` in functions that already return a `Result`:
https://rust-lang.github.io/rust-clippy/master/index.html#/panic_in_result_fn

These lints catch cases like #709, #710 and #712.

The lints have not been enabled for the integration test modules (since using
`unwrap()` is fine there), or to the example buildpacks, since it's a lot of boilerplate
to add to an example.

Very soon we will be able to switch to the upcoming `[lints]` table feature, which will
mean the duplication of lint definitions can be avoided entirely:
https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#lints

GUS-W-14413286.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working libcnb-test
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant