From 079156d86acbe1f4ebbe02215fc5adf76a3359fa Mon Sep 17 00:00:00 2001 From: NicolasCantu Date: Fri, 24 Jan 2025 16:00:21 +0100 Subject: [PATCH] [bug] remove_all_concurrent_states won't panic if there's no concurrent states --- src/process.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/process.rs b/src/process.rs index a49bf51..474e9c6 100644 --- a/src/process.rs +++ b/src/process.rs @@ -169,7 +169,6 @@ impl ProcessState { } }; - // Check if each modified field satisfies at least one applicable rule across all roles let all_fields_validated = modified_fields.iter().all(|field| { // Collect applicable rules from all roles for the current field @@ -450,14 +449,19 @@ impl Process { let empty_state = self.states.pop().unwrap(); let last_commitment_outpoint = empty_state.commited_in; - let split_index = self.states.iter().position(|state| state.commited_in == last_commitment_outpoint).unwrap(); + if let Some(split_index) = self.states.iter().position(|state| state.commited_in == last_commitment_outpoint) { + let removed = self.states.split_off(split_index); - let removed = self.states.split_off(split_index); + // We make sure we always have an empty state at the end + self.states.push(empty_state); - // We make sure we always have an empty state at the end - self.states.push(empty_state); - - Ok(removed) + Ok(removed) + } else { + // This could happen if we weren't aware there was pending concurrent updates + // We push the empty state back and return an empty vec + self.states.push(empty_state); + Ok(vec![]) + } } pub fn get_latest_commited_state(&self) -> Option<&ProcessState> {