Skip to content

Commit

Permalink
update for PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jeddai committed Jun 5, 2023
1 parent 3b22213 commit 3630ef2
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components/support/nimbus-fml/src/error.rs
Expand Up @@ -49,7 +49,7 @@ pub enum FMLError {
#[error("Feature `{0}` not found on manifest")]
InvalidFeatureError(String),
#[error("Property `{0}` not found on feature `{1}`")]
InvalidPropError(String, String),
InvalidPropertyError(String, String),
}

#[cfg(feature = "client-lib")]
Expand Down
2 changes: 1 addition & 1 deletion components/support/nimbus-fml/src/fml.udl
Expand Up @@ -5,7 +5,7 @@ enum FMLError {
"IOError", "JSONError", "YAMLError", "UrlError", "FetchError", "InvalidPath",
"TemplateProblem", "Fatal", "InternalError", "ValidationError", "TypeParsingError",
"InvalidChannelError", "FMLModuleError", "CliError", "ClientError", "InvalidFeatureError",
"InvalidPropError"
"InvalidPropertyError"
};

dictionary MergedJsonWithErrors {
Expand Down
48 changes: 48 additions & 0 deletions components/support/nimbus-fml/src/intermediate_representation.rs
Expand Up @@ -1978,4 +1978,52 @@ pub mod unit_tests {

Ok(())
}

#[test]
fn test_validate_feature_config_errors_on_invalid_object_prop() -> Result<()> {
let obj_defs = vec![ObjectDef {
name: "SampleObj".into(),
props: vec![PropDef {
name: "string".into(),
typ: TypeRef::String,
doc: "".into(),
default: json!("a string"),
}],
..Default::default()
}];
let fm = get_feature_manifest(
obj_defs,
vec![],
vec![FeatureDef {
name: "feature".into(),
props: vec![PropDef {
name: "prop_1".into(),
typ: TypeRef::Object("SampleObj".into()),
default: json!({
"string": "a value"
}),
doc: "".into(),
}],
..Default::default()
}],
HashMap::new(),
);

let result = fm.validate_feature_config(
"feature",
json!({
"prop_1": {
"invalid-prop": "invalid-prop value"
}
}),
);

assert!(result.is_err());
assert_eq!(
result.err().unwrap().to_string(),
"Validation Error at features/feature.prop_1#SampleObj: Default includes key invalid-prop that doesn't exist in SampleObj's object definition"
);

Ok(())
}
}
2 changes: 1 addition & 1 deletion components/support/nimbus-fml/src/parser.rs
Expand Up @@ -569,7 +569,7 @@ impl<'object> DefaultsMerger<'object> {
res.default = v.clone();
Ok(res)
} else {
Err(FMLError::InvalidPropError(k.clone(), res.name.clone()))
Err(FMLError::InvalidPropertyError(k.clone(), res.name.clone()))
}
})
.collect::<Result<Vec<_>>>()?;
Expand Down

0 comments on commit 3630ef2

Please sign in to comment.