Skip to content

Commit

Permalink
Mutations: improve the error on wrong structure for checks (#510)
Browse files Browse the repository at this point in the history
### What

We improve the error message on receiving an unexpected structure for
checks in experimental mutations.

### How

Instead of "Argument not found" we say "Unexpected Structure".
  • Loading branch information
Gil Mizrahi committed Jun 25, 2024
1 parent 6b1494b commit 703bc93
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ pub fn translate(
.ok_or(Error::ArgumentNotFound(pre_check.argument_name.clone()))?;

let predicate: models::Expression = serde_json::from_value(predicate_json.clone())
.map_err(|_| Error::ArgumentNotFound(pre_check.argument_name.clone()))?;
.map_err(|_| {
Error::UnexpectedStructure(format!(
"Argument '{}' should have an ndc-spec Expression structure",
pre_check.argument_name.clone()
))
})?;

let predicate_expression = filtering::translate_expression(
env,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,13 @@ pub fn translate(
mutation.post_check.argument_name.clone(),
))?;

let predicate: models::Expression = serde_json::from_value(predicate_json.clone())
.map_err(|_| Error::ArgumentNotFound(mutation.post_check.argument_name.clone()))?;
let predicate: models::Expression =
serde_json::from_value(predicate_json.clone()).map_err(|_| {
Error::UnexpectedStructure(format!(
"Argument '{}' should have an ndc-spec Expression structure",
mutation.post_check.argument_name.clone()
))
})?;

let predicate_expression = filtering::translate_expression(
env,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ pub fn translate(

let pre_predicate: models::Expression =
serde_json::from_value(pre_predicate_json.clone()).map_err(|_| {
Error::ArgumentNotFound(mutation.pre_check.argument_name.clone())
Error::UnexpectedStructure(format!(
"Argument '{}' should have an ndc-spec Expression structure",
mutation.pre_check.argument_name.clone()
))
})?;

let pre_predicate_expression = filtering::translate_expression(
Expand All @@ -183,7 +186,10 @@ pub fn translate(

let post_predicate: models::Expression =
serde_json::from_value(post_predicate_json.clone()).map_err(|_| {
Error::ArgumentNotFound(mutation.post_check.argument_name.clone())
Error::UnexpectedStructure(format!(
"Argument '{}' should have an ndc-spec Expression structure",
mutation.post_check.argument_name.clone()
))
})?;

let post_predicate_expression = filtering::translate_expression(
Expand Down

0 comments on commit 703bc93

Please sign in to comment.