Skip to content

Commit

Permalink
manifest: Improve error messages for invalid component IDs
Browse files Browse the repository at this point in the history
Signed-off-by: Lann Martin <[email protected]>
  • Loading branch information
lann committed Nov 13, 2023
1 parent 40bbead commit 97a85b9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
16 changes: 15 additions & 1 deletion crates/manifest/src/schema/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,28 @@ pub struct OneOrManyComponentSpecs(#[serde(with = "one_or_many")] pub Vec<Compon

/// Component reference or inline definition
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields, untagged)]
#[serde(deny_unknown_fields, untagged, try_from = "toml::Value")]
pub enum ComponentSpec {
/// `"component-id"`
Reference(KebabId),
/// `{ ... }`
Inline(Box<Component>),
}

impl TryFrom<toml::Value> for ComponentSpec {
type Error = toml::de::Error;

fn try_from(value: toml::Value) -> Result<Self, Self::Error> {
if value.is_str() {
Ok(ComponentSpec::Reference(KebabId::deserialize(value)?))
} else {
Ok(ComponentSpec::Inline(Box::new(Component::deserialize(
value,
)?)))
}
}
}

/// Component definition
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
Expand Down
6 changes: 6 additions & 0 deletions crates/manifest/tests/ui/invalid/bad_kebab_component_ref.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
TOML parse error at line 7, column 13
|
7 | component = "1-2-3"
| ^^^^^^^
'-'-separated words must start with an ASCII letter; got '1'

7 changes: 7 additions & 0 deletions crates/manifest/tests/ui/invalid/bad_kebab_component_ref.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
spin_manifest_version = 2

[application]
name = "minimal-v2"

[[trigger.fake]]
component = "1-2-3"

0 comments on commit 97a85b9

Please sign in to comment.