From e12a6e76cee05ae8366dd19119fd1f940f81e0d0 Mon Sep 17 00:00:00 2001 From: Manuel Fuchs Date: Thu, 8 Feb 2024 18:22:03 +0100 Subject: [PATCH] Use `inspect_err` for tracing errors (#774) --- CHANGELOG.md | 1 + Cargo.toml | 2 +- README.md | 2 +- libcnb-cargo/README.md | 2 +- libcnb-common/README.md | 2 +- libcnb-data/README.md | 2 +- libcnb-package/README.md | 2 +- libcnb-proc-macros/README.md | 2 +- libcnb-test/README.md | 2 +- libcnb/src/runtime.rs | 91 ++++++++++++------------------------ libherokubuildpack/README.md | 2 +- 11 files changed, 41 insertions(+), 69 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8dfb55e4..0bf29ec6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Improved the consistency of cross-compilation assistance provided across all supported `target_triple` and host OS/architecture combinations. [#769](https://github.com/heroku/libcnb.rs/pull/769) - Added cross-compilation assistance for `aarch64-unknown-linux-musl` (on macOS and ARM64 Linux) and `x86_64-unknown-linux-musl` (on ARM64 Linux). [#769](https://github.com/heroku/libcnb.rs/pull/769) +- Raised Minimum Supported Rust Version (MSRV) to `1.76`. ([#774](https://github.com/heroku/libcnb.rs/pull/774)) - `libcnb`: - Changed `Layer` interface from `&self` to `&mut self`. ([#669](https://github.com/heroku/libcnb.rs/pull/669)) diff --git a/Cargo.toml b/Cargo.toml index d2f68474..84327113 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ members = [ [workspace.package] version = "0.17.0" -rust-version = "1.75" +rust-version = "1.76" edition = "2021" license = "BSD-3-Clause" diff --git a/README.md b/README.md index 67e788b5..1e228a98 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [docs.rs]: https://docs.rs/libcnb/latest/libcnb/ [Latest Version]: https://img.shields.io/crates/v/libcnb.svg [crates.io]: https://crates.io/crates/libcnb -[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.74+-lightgray.svg +[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.76+-lightgray.svg [install-rust]: https://www.rust-lang.org/tools/install `libcnb.rs` is a framework for writing [Cloud Native Buildpacks](https://buildpacks.io) in Rust. diff --git a/libcnb-cargo/README.md b/libcnb-cargo/README.md index b0c41f22..f530e8b2 100644 --- a/libcnb-cargo/README.md +++ b/libcnb-cargo/README.md @@ -53,5 +53,5 @@ pack build my-image-name \ [Latest Version]: https://img.shields.io/crates/v/libcnb-cargo.svg [crates.io]: https://crates.io/crates/libcnb-cargo -[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.74+-lightgray.svg +[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.76+-lightgray.svg [install-rust]: https://www.rust-lang.org/tools/install diff --git a/libcnb-common/README.md b/libcnb-common/README.md index 5014d8d5..861df49f 100644 --- a/libcnb-common/README.md +++ b/libcnb-common/README.md @@ -8,5 +8,5 @@ This is an internal crate and should not be used by users directly. There are no [docs.rs]: https://docs.rs/libcnb-proc-macros/latest/libcnb_common/ [Latest Version]: https://img.shields.io/crates/v/libcnb-common.svg [crates.io]: https://crates.io/crates/libcnb-common -[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.74+-lightgray.svg +[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.76+-lightgray.svg [install-rust]: https://www.rust-lang.org/tools/install diff --git a/libcnb-data/README.md b/libcnb-data/README.md index cde3272c..63ee2e67 100644 --- a/libcnb-data/README.md +++ b/libcnb-data/README.md @@ -10,5 +10,5 @@ on this crate directly. [docs.rs]: https://docs.rs/libcnb-data/latest/libcnb_data/ [Latest Version]: https://img.shields.io/crates/v/libcnb-data.svg [crates.io]: https://crates.io/crates/libcnb-data -[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.74+-lightgray.svg +[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.76+-lightgray.svg [install-rust]: https://www.rust-lang.org/tools/install diff --git a/libcnb-package/README.md b/libcnb-package/README.md index 25386e0c..37c27a2b 100644 --- a/libcnb-package/README.md +++ b/libcnb-package/README.md @@ -12,5 +12,5 @@ directly. [docs.rs]: https://docs.rs/libcnb-package/latest/libcnb_package/ [Latest Version]: https://img.shields.io/crates/v/libcnb-package.svg [crates.io]: https://crates.io/crates/libcnb-package -[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.74+-lightgray.svg +[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.76+-lightgray.svg [install-rust]: https://www.rust-lang.org/tools/install diff --git a/libcnb-proc-macros/README.md b/libcnb-proc-macros/README.md index 85c369d7..29a06d3e 100644 --- a/libcnb-proc-macros/README.md +++ b/libcnb-proc-macros/README.md @@ -9,5 +9,5 @@ depending on this crate directly. [docs.rs]: https://docs.rs/libcnb-proc-macros/latest/libcnb_proc_macros/ [Latest Version]: https://img.shields.io/crates/v/libcnb-proc-macros.svg [crates.io]: https://crates.io/crates/libcnb-proc-macros -[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.74+-lightgray.svg +[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.76+-lightgray.svg [install-rust]: https://www.rust-lang.org/tools/install diff --git a/libcnb-test/README.md b/libcnb-test/README.md index ee4ae648..289e254b 100644 --- a/libcnb-test/README.md +++ b/libcnb-test/README.md @@ -226,5 +226,5 @@ fn additional_buildpacks() { [docs.rs]: https://docs.rs/libcnb-test/latest/libcnb_test/ [Latest Version]: https://img.shields.io/crates/v/libcnb-test.svg [crates.io]: https://crates.io/crates/libcnb-test -[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.74+-lightgray.svg +[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.76+-lightgray.svg [install-rust]: https://www.rust-lang.org/tools/install diff --git a/libcnb/src/runtime.rs b/libcnb/src/runtime.rs index 6f6a5870..3025b544 100644 --- a/libcnb/src/runtime.rs +++ b/libcnb/src/runtime.rs @@ -143,16 +143,11 @@ pub fn libcnb_runtime_detect( let stack_id: StackId = env::var("CNB_STACK_ID") .map_err(Error::CannotDetermineStackId) .and_then(|stack_id_string| stack_id_string.parse().map_err(Error::StackIdError)) - .map_err(|err| { - trace_error(&err); - err - })?; + .inspect_err(|err| trace_error(err))?; - let platform = B::Platform::from_path(&args.platform_dir_path).map_err(|inner_err| { - let err = Error::CannotCreatePlatformFromPath(inner_err); - trace_error(&err); - err - })?; + let platform = B::Platform::from_path(&args.platform_dir_path) + .map_err(Error::CannotCreatePlatformFromPath) + .inspect_err(|err| trace_error(err))?; let build_plan_path = args.build_plan_path; @@ -164,10 +159,9 @@ pub fn libcnb_runtime_detect( buildpack_descriptor, }; - let detect_result = buildpack.detect(detect_context).map_err(|err| { - trace_error(&err); - err - })?; + let detect_result = buildpack + .detect(detect_context) + .inspect_err(|err| trace_error(err))?; match detect_result.0 { InnerDetectResult::Fail => { @@ -177,11 +171,9 @@ pub fn libcnb_runtime_detect( } InnerDetectResult::Pass { build_plan } => { if let Some(build_plan) = build_plan { - write_toml_file(&build_plan, build_plan_path).map_err(|inner_err| { - let err = Error::CannotWriteBuildPlan(inner_err); - trace_error(&err); - err - })?; + write_toml_file(&build_plan, build_plan_path) + .map_err(Error::CannotWriteBuildPlan) + .inspect_err(|err| trace_error(err))?; } #[cfg(feature = "trace")] trace.add_event("detect-passed"); @@ -222,32 +214,22 @@ pub fn libcnb_runtime_build( let stack_id: StackId = env::var("CNB_STACK_ID") .map_err(Error::CannotDetermineStackId) .and_then(|stack_id_string| stack_id_string.parse().map_err(Error::StackIdError)) - .map_err(|err| { - trace_error(&err); - err - })?; - - let platform = Platform::from_path(&args.platform_dir_path).map_err(|inner_err| { - let err = Error::CannotCreatePlatformFromPath(inner_err); - trace_error(&err); - err - })?; - - let buildpack_plan = read_toml_file(&args.buildpack_plan_path).map_err(|inner_err| { - let err = Error::CannotReadBuildpackPlan(inner_err); - trace_error(&err); - err - })?; + .inspect_err(|err| trace_error(err))?; + + let platform = Platform::from_path(&args.platform_dir_path) + .map_err(Error::CannotCreatePlatformFromPath) + .inspect_err(|err| trace_error(err))?; + + let buildpack_plan = read_toml_file(&args.buildpack_plan_path) + .map_err(Error::CannotReadBuildpackPlan) + .inspect_err(|err| trace_error(err))?; let store = match read_toml_file::(layers_dir.join("store.toml")) { Err(TomlFileError::IoError(io_error)) if is_not_found_error_kind(&io_error) => Ok(None), other => other.map(Some), } .map_err(Error::CannotReadStore) - .map_err(|err| { - trace_error(&err); - err - })?; + .inspect_err(|err| trace_error(err))?; let build_context = BuildContext { layers_dir: layers_dir.clone(), @@ -260,10 +242,9 @@ pub fn libcnb_runtime_build( store, }; - let build_result = buildpack.build(build_context).map_err(|err| { - trace_error(&err); - err - })?; + let build_result = buildpack + .build(build_context) + .inspect_err(|err| trace_error(err))?; match build_result.0 { InnerBuildResult::Pass { @@ -273,19 +254,15 @@ pub fn libcnb_runtime_build( launch_sboms, } => { if let Some(launch) = launch { - write_toml_file(&launch, layers_dir.join("launch.toml")).map_err(|inner_err| { - let err = Error::CannotWriteLaunch(inner_err); - trace_error(&err); - err - })?; + write_toml_file(&launch, layers_dir.join("launch.toml")) + .map_err(Error::CannotWriteLaunch) + .inspect_err(|err| trace_error(err))?; }; if let Some(store) = store { - write_toml_file(&store, layers_dir.join("store.toml")).map_err(|inner_err| { - let err = Error::CannotWriteStore(inner_err); - trace_error(&err); - err - })?; + write_toml_file(&store, layers_dir.join("store.toml")) + .map_err(Error::CannotWriteStore) + .inspect_err(|err| trace_error(err))?; }; for build_sbom in build_sboms { @@ -294,10 +271,7 @@ pub fn libcnb_runtime_build( &build_sbom.data, ) .map_err(Error::CannotWriteBuildSbom) - .map_err(|err| { - trace_error(&err); - err - })?; + .inspect_err(|err| trace_error(err))?; } for launch_sbom in launch_sboms { @@ -306,10 +280,7 @@ pub fn libcnb_runtime_build( &launch_sbom.data, ) .map_err(Error::CannotWriteLaunchSbom) - .map_err(|err| { - trace_error(&err); - err - })?; + .inspect_err(|err| trace_error(err))?; } #[cfg(feature = "trace")] diff --git a/libherokubuildpack/README.md b/libherokubuildpack/README.md index 3954e651..b919e4db 100644 --- a/libherokubuildpack/README.md +++ b/libherokubuildpack/README.md @@ -37,5 +37,5 @@ The feature names line up with the modules in this crate. All features are enabl [docs.rs]: https://docs.rs/libherokubuildpack/latest/libherokubuildpack/ [Latest Version]: https://img.shields.io/crates/v/libherokubuildpack.svg [crates.io]: https://crates.io/crates/libherokubuildpack -[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.74+-lightgray.svg +[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.76+-lightgray.svg [install-rust]: https://www.rust-lang.org/tools/install