Skip to content

Commit 87e8e14

Browse files
committed
fix: Improve validation errors
1 parent 7afd0b1 commit 87e8e14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+2668
-391
lines changed

Cargo.lock

Lines changed: 165 additions & 171 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ tempfile.workspace = true
102102
tokio = { workspace = true, optional = true }
103103
bon.workspace = true
104104
users.workspace = true
105+
thiserror = "2.0.7"
105106

106107
[features]
107108
# Top level features

recipe/src/module.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::{borrow::Cow, path::PathBuf};
22

3-
use blue_build_utils::syntax_highlighting::highlight_ser;
3+
use blue_build_utils::{
4+
constants::BLUE_BUILD_MODULE_IMAGE_REF, syntax_highlighting::highlight_ser,
5+
};
46
use bon::Builder;
57
use colored::Colorize;
68
use indexmap::IndexMap;
@@ -95,6 +97,15 @@ impl<'a> ModuleRequiredFields<'a> {
9597
}
9698
}
9799

100+
#[must_use]
101+
pub fn get_module_image(&self) -> String {
102+
format!(
103+
"{BLUE_BUILD_MODULE_IMAGE_REF}/{}:{}",
104+
self.module_type.typ(),
105+
self.module_type.version().unwrap_or("latest")
106+
)
107+
}
108+
98109
#[must_use]
99110
pub fn is_local_source(&self) -> bool {
100111
self.source

recipe/src/module/type_ver.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use serde::{Deserialize, Deserializer, Serialize};
55
#[derive(Debug, Clone)]
66
pub struct ModuleTypeVersion<'scope> {
77
typ: Cow<'scope, str>,
8-
version: Cow<'scope, str>,
8+
version: Option<Cow<'scope, str>>,
99
}
1010

1111
impl ModuleTypeVersion<'_> {
@@ -15,14 +15,21 @@ impl ModuleTypeVersion<'_> {
1515
}
1616

1717
#[must_use]
18-
pub fn version(&self) -> &str {
19-
&self.version
18+
pub fn version(&self) -> Option<&str> {
19+
self.version.as_deref()
2020
}
2121
}
2222

2323
impl std::fmt::Display for ModuleTypeVersion<'_> {
2424
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25-
write!(f, "{}@{}", &self.typ, &self.version)
25+
match self.version.as_deref() {
26+
Some(version) => {
27+
write!(f, "{}@{version}", &self.typ)
28+
}
29+
None => {
30+
write!(f, "{}", &self.typ)
31+
}
32+
}
2633
}
2734
}
2835

@@ -31,12 +38,12 @@ impl<'scope> From<&'scope str> for ModuleTypeVersion<'scope> {
3138
if let Some((typ, version)) = s.split_once('@') {
3239
Self {
3340
typ: Cow::Borrowed(typ),
34-
version: Cow::Borrowed(version),
41+
version: Some(Cow::Borrowed(version)),
3542
}
3643
} else {
3744
Self {
3845
typ: Cow::Borrowed(s),
39-
version: Cow::Owned("latest".into()),
46+
version: None,
4047
}
4148
}
4249
}
@@ -47,12 +54,12 @@ impl From<String> for ModuleTypeVersion<'_> {
4754
if let Some((typ, version)) = s.split_once('@') {
4855
Self {
4956
typ: Cow::Owned(typ.to_owned()),
50-
version: Cow::Owned(version.to_owned()),
57+
version: Some(Cow::Owned(version.to_owned())),
5158
}
5259
} else {
5360
Self {
5461
typ: Cow::Owned(s),
55-
version: Cow::Owned("latest".into()),
62+
version: None,
5663
}
5764
}
5865
}

src/commands/validate.rs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,21 @@ impl BlueBuildCommand for ValidateCommand {
9797
impl ValidateCommand {
9898
async fn setup_validators(&mut self) -> Result<(), Report> {
9999
let (rv, sv, mv, mslv) = tokio::try_join!(
100-
SchemaValidator::builder().url(RECIPE_V1_SCHEMA_URL).build(),
101-
SchemaValidator::builder().url(STAGE_V1_SCHEMA_URL).build(),
102-
SchemaValidator::builder().url(MODULE_V1_SCHEMA_URL).build(),
100+
SchemaValidator::builder()
101+
.url(RECIPE_V1_SCHEMA_URL)
102+
.all_errors(self.all_errors)
103+
.build(),
104+
SchemaValidator::builder()
105+
.url(STAGE_V1_SCHEMA_URL)
106+
.all_errors(self.all_errors)
107+
.build(),
108+
SchemaValidator::builder()
109+
.url(MODULE_V1_SCHEMA_URL)
110+
.all_errors(self.all_errors)
111+
.build(),
103112
SchemaValidator::builder()
104113
.url(MODULE_STAGE_LIST_V1_SCHEMA_URL)
114+
.all_errors(self.all_errors)
105115
.build(),
106116
)?;
107117
self.recipe_validator = Some(rv);
@@ -149,15 +159,12 @@ impl ValidateCommand {
149159

150160
if instance.get(DF::LIST_KEY).is_some() {
151161
debug!("{path_display} is a list file");
152-
let err = match self
162+
let err = self
153163
.module_stage_list_validator
154164
.as_ref()
155165
.unwrap()
156-
.process_validation(path, file_str.clone(), self.all_errors)
157-
{
158-
Err(e) => return vec![e],
159-
Ok(e) => e,
160-
};
166+
.process_validation(path, file_str.clone())
167+
.err();
161168

162169
err.map_or_else(
163170
|| {
@@ -195,13 +202,13 @@ impl ValidateCommand {
195202
},
196203
)
197204
},
198-
|err| vec![err],
205+
|err| vec![err.into()],
199206
)
200207
} else {
201208
debug!("{path_display} is a single file file");
202209
single_validator
203-
.process_validation(path, file_str, self.all_errors)
204-
.map_or_else(|e| vec![e], |e| e.map_or_else(Vec::new, |e| vec![e]))
210+
.process_validation(path, file_str)
211+
.map_or_else(|e| vec![e.into()], |()| Vec::new())
205212
}
206213
}
207214
Err(e) => vec![e],
@@ -221,11 +228,11 @@ impl ValidateCommand {
221228

222229
let schema_validator = self.recipe_validator.as_ref().unwrap();
223230
let err = schema_validator
224-
.process_validation(&self.recipe, recipe_str.clone(), self.all_errors)
225-
.map_err(err_vec)?;
231+
.process_validation(&self.recipe, recipe_str.clone())
232+
.err();
226233

227234
if let Some(err) = err {
228-
Err(vec![err])
235+
Err(vec![err.into()])
229236
} else {
230237
let recipe: Recipe = serde_yaml::from_str(&recipe_str)
231238
.into_diagnostic()

src/commands/validate/location.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ impl From<&JsonLocation> for Location {
3535
}
3636
}
3737

38+
impl std::fmt::Display for Location {
39+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40+
self.0.fmt(f)
41+
}
42+
}
43+
3844
impl TryFrom<&str> for Location {
3945
type Error = miette::Report;
4046

0 commit comments

Comments
 (0)