Skip to content

Commit

Permalink
Use expect() for OS and arch parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Malax committed May 21, 2024
1 parent a8b5e14 commit b4abf17
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 30 deletions.
26 changes: 1 addition & 25 deletions buildpacks/jvm/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,31 +132,7 @@ pub(crate) fn on_error_jvm_buildpack(error: OpenJdkBuildpackError) {
", version = version },
)
}
}
OpenJdkBuildpackError::UnsupportedOsError(error) => log_error(
"Unsupported Operating System",
formatdoc! {"
The target operating system for this build is not supported. This error should
never occur to users of this buildpack.
If you see this error, please file an issue:
https://github.com/heroku/buildpacks-jvm/issues/new
Details: {error}
", error = error },
),
OpenJdkBuildpackError::UnsupportedArchError(error) => log_error(
"Unsupported System Architecture",
formatdoc! {"
The target system architecture for this build is not supported. This error should
never occur to users of this buildpack.
If you see this error, please file an issue:
https://github.com/heroku/buildpacks-jvm/issues/new
Details: {error}
", error = error },
),
},
OpenJdkBuildpackError::ParseInventoryError(error) => log_error(
"Invalid Inventory File",
formatdoc! {"
Expand Down
8 changes: 3 additions & 5 deletions buildpacks/jvm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use buildpacks_jvm_shared::system_properties::{read_system_properties, ReadSyste
pub(crate) use constants::{
JAVA_TOOL_OPTIONS_ENV_VAR_DELIMITER, JAVA_TOOL_OPTIONS_ENV_VAR_NAME, JDK_OVERLAY_DIR_NAME,
};
use inventory::artifact::{Arch, Os, UnsupportedArchError, UnsupportedOsError};
use inventory::artifact::{Arch, Os};
use inventory::inventory::{Inventory, ParseInventoryError};
use libcnb::build::{BuildContext, BuildResult, BuildResultBuilder};
use libcnb::data::build_plan::BuildPlanBuilder;
Expand Down Expand Up @@ -56,8 +56,6 @@ enum OpenJdkBuildpackError {
CannotListJdkOverlayContents(std::io::Error),
CannotCopyJdkOverlayContents(fs_extra::error::Error),
ParseInventoryError(ParseInventoryError),
UnsupportedOsError(UnsupportedOsError),
UnsupportedArchError(UnsupportedArchError),
}

impl Buildpack for OpenJdkBuildpack {
Expand Down Expand Up @@ -115,12 +113,12 @@ impl Buildpack for OpenJdkBuildpack {
.target
.os
.parse::<Os>()
.map_err(OpenJdkBuildpackError::UnsupportedOsError)?,
.expect("OS should be always parseable, buildpack will not run on unsupported operating systems."),
context
.target
.arch
.parse::<Arch>()
.map_err(OpenJdkBuildpackError::UnsupportedArchError)?,
.expect("arch should be always parseable, buildpack will not run on unsupported architectures."),
&openjdk_artifact_requirement,
)
.ok_or(OpenJdkBuildpackError::UnsupportedOpenJdkVersion(
Expand Down

0 comments on commit b4abf17

Please sign in to comment.