Skip to content

Commit e090bf0

Browse files
committed
feat(boil): Improve empty image version filter error
This now reports the image name and the filtered version(s) in the error. Previously, users would have to guess which image and version yielded an empty list.
1 parent b4a8a25 commit e090bf0

2 files changed

Lines changed: 25 additions & 16 deletions

File tree

rust/boil/src/core/bakefile.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,17 @@ pub enum Error {
7070

7171
#[derive(Debug, Snafu)]
7272
pub enum TargetsError {
73-
#[snafu(display("encountered invalid image version"))]
74-
InvalidImageVersion { source: ImageConfigError },
75-
7673
#[snafu(display("failed to read image config"))]
7774
ReadImageConfig { source: ImageConfigError },
7875

7976
#[snafu(display("failed to resolve parent directory of image config at {path}", path = path.display()))]
8077
ResolveParentDirectory { path: PathBuf },
78+
79+
#[snafu(display("provided filter version(s) ({image_name}={versions}) yielded empty list", versions = versions.join(", ")))]
80+
EmptyFilter {
81+
versions: Vec<String>,
82+
image_name: String,
83+
},
8184
}
8285

8386
#[derive(Debug, Default)]
@@ -187,9 +190,15 @@ impl Targets {
187190
ImageConfig::from_file(image_config_path).context(ReadImageConfigSnafu)?;
188191

189192
// Create a list of image versions we need to generate targets for in the bakefile.
190-
image_config
191-
.filter_by_version(&image.versions)
192-
.context(InvalidImageVersionSnafu)?;
193+
image_config.filter_by_version(&image.versions);
194+
195+
ensure!(
196+
!image_config.versions.is_empty(),
197+
EmptyFilterSnafu {
198+
versions: image.versions.clone(),
199+
image_name: image.name.clone(),
200+
}
201+
);
193202

194203
targets.insert_targets(image.name.clone(), image_config, &options, true)?;
195204
}
@@ -222,9 +231,15 @@ impl Targets {
222231
let mut image_config =
223232
ImageConfig::from_file(image_config_path).context(ReadImageConfigSnafu)?;
224233

225-
image_config
226-
.filter_by_version(&[image_version])
227-
.context(InvalidImageVersionSnafu)?;
234+
image_config.filter_by_version(&[image_version]);
235+
236+
ensure!(
237+
!image_config.versions.is_empty(),
238+
EmptyFilterSnafu {
239+
versions: vec![image_version.clone()],
240+
image_name: image_name.clone(),
241+
}
242+
);
228243

229244
// Wowzers, recursion!
230245
self.insert_targets(image_name.clone(), image_config, options, false)?;

rust/boil/src/core/image.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,6 @@ pub enum ImageConfigError {
108108

109109
#[snafu(display("failed to deserialize config file from TOML"))]
110110
Deserialize { source: toml::de::Error },
111-
112-
#[snafu(display("provided filter version yielded empty list"))]
113-
EmptyFilter,
114111
}
115112

116113
#[derive(Debug, Deserialize)]
@@ -130,16 +127,13 @@ impl ImageConfig {
130127
pub const FLAT_CONFIG_GLOB_PATTERN: &str = "*/boil-config.toml";
131128

132129
/// This function removes versions in the config filtered out by `versions`.
133-
pub fn filter_by_version<V>(&mut self, versions: &[V]) -> Result<(), ImageConfigError>
130+
pub fn filter_by_version<V>(&mut self, versions: &[V])
134131
where
135132
V: AsRef<str> + PartialEq,
136133
{
137134
self.versions.retain(|image_version, _| {
138135
versions.is_empty() || versions.iter().any(|v| v.as_ref() == image_version)
139136
});
140-
141-
ensure!(!self.versions.is_empty(), EmptyFilterSnafu);
142-
Ok(())
143137
}
144138
}
145139

0 commit comments

Comments
 (0)