8000 Use `inspect_err` for tracing errors by Malax · Pull Request #774 · heroku/libcnb.rs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Use inspect_err for tracing errors #774

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 statemen 8000 t. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
8000
Original file line numberDiff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion libcnb-cargo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion libcnb-common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion libcnb-data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion libcnb-package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion libcnb-proc-macros/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion libcnb-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
91 changes: 31 additions & 60 deletions libcnb/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,11 @@ pub fn libcnb_runtime_detect<B: Buildpack>(
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;

Expand All @@ -164,10 +159,9 @@ pub fn libcnb_runtime_detect<B: Buildpack>(
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 => {
Expand All @@ -177,11 +171,9 @@ pub fn libcnb_runtime_detect<B: Buildpack>(
}
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");
Expand Down Expand Up @@ -222,32 +214,22 @@ pub fn libcnb_runtime_build<B: Buildpack>(
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::<Store>(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(),
Expand All @@ -260,10 +242,9 @@ pub fn libcnb_runtime_build<B: Buildpack>(
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 {
Expand All @@ -273,19 +254,15 @@ pub fn libcnb_runtime_build<B: Buildpack>(
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 {
Expand All @@ -294,10 +271,7 @@ pub fn libcnb_runtime_build<B: Buildpack>(
&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 {
Expand All @@ -306,10 +280,7 @@ pub fn libcnb_runtime_build<B: Buildpack>(
&launch_sbom.data,
)
.map_err(Error::CannotWriteLaunchSbom)
.map_err(|err| {
trace_error(&err);
err
})?;
.inspect_err(|err| trace_error(err))?;
}

#[cfg(feature = "trace")]
Expand Down
2 changes: 1 addition & 1 deletion libherokubuildpack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
0