diff --git a/CHANGELOG.md b/CHANGELOG.md index 35f479b3..0139c5eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,5 +36,6 @@ - New trait design for `LayerLifecycle` which also was renamed to `Layer`. - Removed low-level layer functions from `BuildContext`. They don't fit well with the design of the library at this point and are potential footguns. Implementing a `Layer` should work for all use-cases. +- The `stack_id` field in `BuildContext` and `DetectContext` is now of type `StackId` instead of `String`. ## [0.3.0] 2021/09/17 diff --git a/libcnb/src/build.rs b/libcnb/src/build.rs index ee605bad..3be97e91 100644 --- a/libcnb/src/build.rs +++ b/libcnb/src/build.rs @@ -6,6 +6,7 @@ use crate::buildpack::Buildpack; use crate::data::store::Store; use crate::layer::{HandleLayerErrorOrBuildpackError, Layer, LayerData}; +use crate::data::buildpack::StackId; use crate::data::{buildpack::BuildpackToml, buildpack_plan::BuildpackPlan, launch::Launch}; /// Context for the build phase execution. @@ -13,7 +14,7 @@ pub struct BuildContext { pub layers_dir: PathBuf, pub app_dir: PathBuf, pub buildpack_dir: PathBuf, - pub stack_id: String, + pub stack_id: StackId, pub platform: B::Platform, pub buildpack_plan: BuildpackPlan, pub buildpack_descriptor: BuildpackToml, diff --git a/libcnb/src/detect.rs b/libcnb/src/detect.rs index 3f167305..687ad1df 100644 --- a/libcnb/src/detect.rs +++ b/libcnb/src/detect.rs @@ -4,13 +4,14 @@ use std::fmt::Debug; use std::path::PathBuf; use crate::buildpack::Buildpack; +use crate::data::buildpack::StackId; use crate::{data::build_plan::BuildPlan, data::buildpack::BuildpackToml}; /// Context for the detect phase execution. pub struct DetectContext { pub app_dir: PathBuf, pub buildpack_dir: PathBuf, - pub stack_id: String, + pub stack_id: StackId, pub platform: B::Platform, pub buildpack_descriptor: BuildpackToml, } diff --git a/libcnb/src/error.rs b/libcnb/src/error.rs index f6a2c16c..6e0a1538 100644 --- a/libcnb/src/error.rs +++ b/libcnb/src/error.rs @@ -1,3 +1,4 @@ +use crate::data::buildpack::StackIdError; use crate::data::launch::ProcessTypeError; use crate::layer::HandleLayerError; use crate::toml_file::TomlFileError; @@ -17,6 +18,9 @@ pub enum Error { #[error("Process type error: {0}")] ProcessTypeError(#[from] ProcessTypeError), + #[error("Stack ID error: {0}")] + StackIdError(#[from] StackIdError), + #[error("Could not determine app directory: {0}")] CannotDetermineAppDirectory(std::io::Error), diff --git a/libcnb/src/runtime.rs b/libcnb/src/runtime.rs index acc0d664..512a217b 100644 --- a/libcnb/src/runtime.rs +++ b/libcnb/src/runtime.rs @@ -8,7 +8,7 @@ use serde::de::DeserializeOwned; use crate::build::{BuildContext, InnerBuildResult}; use crate::buildpack::Buildpack; -use crate::data::buildpack::BuildpackToml; +use crate::data::buildpack::{BuildpackToml, StackId}; use crate::detect::{DetectContext, InnerDetectResult}; use crate::error::Error; use crate::platform::Platform; @@ -86,7 +86,9 @@ fn libcnb_runtime_detect(buildpack: &B) -> Result<(), B::Error> { let app_dir = env::current_dir().map_err(Error::CannotDetermineAppDirectory)?; - let stack_id: String = env::var("CNB_STACK_ID").map_err(Error::CannotDetermineStackId)?; + 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))?; let platform = B::Platform::from_path(&args.platform_dir_path) .map_err(Error::CannotCreatePlatformFromPath)?; @@ -121,7 +123,9 @@ fn libcnb_runtime_build(buildpack: &B) -> Result<(), B::Error> { let app_dir = env::current_dir().map_err(Error::CannotDetermineAppDirectory)?; - let stack_id: String = env::var("CNB_STACK_ID").map_err(Error::CannotDetermineStackId)?; + 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))?; let platform = B::Platform::from_path(&args.platform_dir_path) .map_err(Error::CannotCreatePlatformFromPath)?;