diff --git a/crates/mind-body/src/projection/commit.rs b/crates/mind-body/src/projection/commit.rs index d956964..bf5ce57 100644 --- a/crates/mind-body/src/projection/commit.rs +++ b/crates/mind-body/src/projection/commit.rs @@ -286,7 +286,7 @@ pub(crate) fn apply(state: &Value, record: &Value, prose: &str, key: &str, now: fn block_on_failed_reads(state: &mut Value, record: &Value, applied: &mut Applied) { let repo_of = |target: &str| target.split(['#', '?', '/', '@']).take(2).collect::>().join("/"); let failed: Vec<&Value> = record["interpreter"]["reads"].as_array().into_iter().flatten().filter(|read| read["ok"] == false && read["failure"] == "not_found").collect(); - for entry in state["commitments"].as_array_mut().into_iter().flatten().filter(|entry| entry["status"] == "open") { + for entry in state.get_mut("commitments").and_then(Value::as_array_mut).into_iter().flatten().filter(|entry| entry["status"] == "open") { let Some(needs) = entry["needs"].as_str().map(str::to_owned) else { continue }; let Some(read) = failed.iter().find(|read| { let target = read["request"]["target"].as_str().unwrap_or_default(); @@ -325,12 +325,12 @@ fn apply_one(state: &mut Value, proposal: &Proposal, record: &Value, prose: &str let listed = record["interpreter"]["promises"].as_array().into_iter().flatten().find(|shown| shown["id"].as_str() == Some(id.trim())).ok_or(Refusal::NoSuchPromise)?; let entries = state["commitments"].as_array_mut().expect("commitments is an array"); let entry = entries.iter_mut().find(|entry| entry["id"] == listed["entry"]).ok_or(Refusal::OutsidePutRemovedTarget)?; - if listed["held"] != *entry { - return Err(Refusal::OutsidePutChanged); - } if !matches!(entry["status"].as_str(), Some("open" | "blocked")) { return Err(Refusal::ReaffirmsClosed); } + if listed["held"] != *entry { + return Err(Refusal::OutsidePutChanged); + } if entry["to"] != json!(to) { return Err(Refusal::ReaffirmsAnother); }