Skip to content

Commit

Permalink
fix: Error where interactions failed to load where being silently ign…
Browse files Browse the repository at this point in the history
…ored #359
  • Loading branch information
rholshausen committed Jan 19, 2024
1 parent 5f29d76 commit 512ed87
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions rust/pact_models/src/v4/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,16 @@ impl PartialEq for Box<dyn V4Interaction + Send + Sync + RefUnwindSafe> {
}

/// Load V4 format interactions from JSON struct
pub fn interactions_from_json(json: &Value, source: &str) -> Vec<Box<dyn V4Interaction + Send + Sync + RefUnwindSafe>> {
pub fn interactions_from_json(json: &Value, source: &str) -> anyhow::Result<Vec<Box<dyn V4Interaction + Send + Sync + RefUnwindSafe>>> {
match json.get("interactions") {
Some(Value::Array(ref array)) => {
array.iter().enumerate().map(|(index, ijson)| {
interaction_from_json(source, index, ijson).ok()
}).flatten()
.collect()
let mut interactions = vec![];
for (index, ijson) in array.iter().enumerate() {
interactions.push(interaction_from_json(source, index, ijson)?);
}
Ok(interactions)
},
_ => vec![]
_ => Ok(vec![])
}
}

Expand Down
4 changes: 2 additions & 2 deletions rust/pact_models/src/v4/pact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl V4Pact {
Ok(V4Pact {
consumer,
provider,
interactions: interactions_from_json(&json, source),
interactions: interactions_from_json(&json, source)?,
metadata,
plugin_data
})
Expand Down Expand Up @@ -447,7 +447,7 @@ pub fn from_json(source: &str, pact_json: &Value) -> anyhow::Result<Box<dyn Pact
Ok(Box::new(V4Pact {
consumer,
provider,
interactions: interactions_from_json(pact_json, source),
interactions: interactions_from_json(pact_json, source)?,
metadata,
plugin_data
}))
Expand Down

0 comments on commit 512ed87

Please sign in to comment.