Skip to content

Commit

Permalink
chore: add a few labels and help texts
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Apr 17, 2024
1 parent dee02fa commit a5d0d06
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
8 changes: 7 additions & 1 deletion src/recipe/custom_yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,13 @@ impl TryConvertNode<Url> for RenderedNode {
impl TryConvertNode<Url> for RenderedScalarNode {
fn try_convert(&self, _name: &str) -> Result<Url, Vec<PartialParsingError>> {
Url::parse(self.as_str())
.map_err(|err| _partialerror!(*self.span(), ErrorKind::from(err)))
.map_err(|err| {
_partialerror!(
*self.span(),
ErrorKind::from(err),
label = "failed to parse URL"
)
})
.map_err(|e| vec![e])
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/recipe/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ impl Recipe {
vec![_partialerror!(
*root_node.span(),
ErrorKind::ExpectedMapping,
help = "root node must always be a map with keys like `package`, `source`, `build`, `requirements`, `tests`, `about`, `context` and `extra`"
)]
})?;

Expand All @@ -173,7 +174,7 @@ impl Recipe {
vec![_partialerror!(
*v.span(),
ErrorKind::ExpectedScalar,
help = "`context` values must always be scalars"
help = "`context` values must always be scalars (strings)"
)]
})?;
let rendered: Option<ScalarNode> =
Expand Down
1 change: 1 addition & 0 deletions src/recipe/parser/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ impl TryConvertNode<EntryPoint> for RenderedScalarNode {
vec![_partialerror!(
*self.span(),
ErrorKind::EntryPointParsing(err),
help = format!("expected a string in the format of `command = module:function`")
)]
})
}
Expand Down
17 changes: 12 additions & 5 deletions src/recipe/parser/glob_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@ impl GlobVec {
impl TryConvertNode<GlobVec> for RenderedNode {
fn try_convert(&self, name: &str) -> Result<GlobVec, Vec<PartialParsingError>> {
self.as_sequence()
.ok_or_else(|| vec![_partialerror!(*self.span(), ErrorKind::ExpectedSequence)])
.ok_or_else(|| {
vec![_partialerror!(
*self.span(),
ErrorKind::ExpectedSequence,
label = format!("expected a list of globs strings for '{}'", name)
)]
})
.and_then(|s| s.try_convert(name))
}
}
Expand Down Expand Up @@ -195,10 +201,11 @@ impl TryConvertNode<AllOrGlobVec> for RenderedNode {
} else if let Some(scalar) = self.as_scalar() {
scalar.try_convert(name)
} else {
Err(vec![
_partialerror!(*self.span(), ErrorKind::ExpectedScalar),
_partialerror!(*self.span(), ErrorKind::ExpectedSequence),
])
Err(vec![_partialerror!(
*self.span(),
ErrorKind::ExpectedScalar,
label = "expected a boolean value or a sequence of glob strings"
)])
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/recipe/parser/requirements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl TryConvertNode<Vec<Dependency>> for RenderedNode {
RenderedNode::Mapping(_) => Err(vec![_partialerror!(
*self.span(),
ErrorKind::Other,
label = "expected scalar or sequence"
label = format!("expected scalar or sequence for `{name}`")
)]),
RenderedNode::Null(_) => Ok(vec![]),
}
Expand Down Expand Up @@ -512,7 +512,13 @@ impl IgnoreRunExports {
impl TryConvertNode<IgnoreRunExports> for RenderedNode {
fn try_convert(&self, name: &str) -> Result<IgnoreRunExports, Vec<PartialParsingError>> {
self.as_mapping()
.ok_or_else(|| vec![_partialerror!(*self.span(), ErrorKind::ExpectedMapping)])
.ok_or_else(|| {
vec![_partialerror!(
*self.span(),
ErrorKind::ExpectedMapping,
label = format!("expected a mapping for `{name}`")
)]
})
.and_then(|m| m.try_convert(name))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/recipe/parser/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ impl TryConvertNode<Script> for RenderedMappingNode {
return Err(vec![_partialerror!(
*last_node.span(),
ErrorKind::InvalidField(last_node_name.into()),
help = format!("cannot specify both `content` and `file`")
help = "cannot specify both `content` and `file`"
)]);
}
(Some(file), None) => file.try_convert("file").map(ScriptContent::Path)?,
Expand Down

0 comments on commit a5d0d06

Please sign in to comment.