diff --git a/simulator/generation/plan.rs b/simulator/generation/plan.rs index 028da2a30..9acef25ad 100644 --- a/simulator/generation/plan.rs +++ b/simulator/generation/plan.rs @@ -167,7 +167,7 @@ impl Display for Interaction { } } -type AssertionFunc = dyn Fn(&Vec, &SimulatorEnv) -> bool; +type AssertionFunc = dyn Fn(&Vec, &SimulatorEnv) -> Result; enum AssertionAST { Pick(), @@ -375,12 +375,17 @@ impl Interaction { unreachable!("unexpected: this function should only be called on assertions") } Self::Assertion(assertion) => { - if !assertion.func.as_ref()(stack, env) { - return Err(limbo_core::LimboError::InternalError( + let result = assertion.func.as_ref()(stack, env); + match result { + Ok(true) => Ok(()), + Ok(false) => Err(limbo_core::LimboError::InternalError( assertion.message.clone(), - )); + )), + Err(err) => Err(limbo_core::LimboError::InternalError(format!( + "{}. Inner error: {}", + assertion.message, err + ))), } - Ok(()) } Self::Assumption(_) => { unreachable!("unexpected: this function should only be called on assertions") @@ -404,12 +409,17 @@ impl Interaction { unreachable!("unexpected: this function should only be called on assumptions") } Self::Assumption(assumption) => { - if !assumption.func.as_ref()(stack, env) { - return Err(limbo_core::LimboError::InternalError( + let result = assumption.func.as_ref()(stack, env); + match result { + Ok(true) => Ok(()), + Ok(false) => Err(limbo_core::LimboError::InternalError( assumption.message.clone(), - )); + )), + Err(err) => Err(limbo_core::LimboError::InternalError(format!( + "{}. Inner error: {}", + assumption.message, err + ))), } - Ok(()) } Self::Fault(_) => { unreachable!("unexpected: this function should only be called on assumptions") diff --git a/simulator/generation/property.rs b/simulator/generation/property.rs index dd92a7af8..cae2a4145 100644 --- a/simulator/generation/property.rs +++ b/simulator/generation/property.rs @@ -1,3 +1,5 @@ +use limbo_core::LimboError; + use crate::{ model::{ query::{Create, Delete, Insert, Predicate, Query, Select}, @@ -94,7 +96,7 @@ impl Property { func: Box::new({ let table_name = insert.table.clone(); move |_: &Vec, env: &SimulatorEnv| { - env.tables.iter().any(|t| t.name == table_name) + Ok(env.tables.iter().any(|t| t.name == table_name)) } }), }); @@ -109,8 +111,8 @@ impl Property { func: Box::new(move |stack: &Vec, _: &SimulatorEnv| { let rows = stack.last().unwrap(); match rows { - Ok(rows) => rows.iter().any(|r| r == &row), - Err(_) => false, + Ok(rows) => Ok(rows.iter().any(|r| r == &row)), + Err(err) => Err(LimboError::InternalError(err.to_string())), } }), }); @@ -131,7 +133,7 @@ impl Property { message: "Double-Create-Failure should not be called on an existing table" .to_string(), func: Box::new(move |_: &Vec, env: &SimulatorEnv| { - !env.tables.iter().any(|t| t.name == table_name) + Ok(!env.tables.iter().any(|t| t.name == table_name)) }), }); @@ -147,10 +149,8 @@ impl Property { func: Box::new(move |stack: &Vec, _: &SimulatorEnv| { let last = stack.last().unwrap(); match last { - Ok(_) => false, - Err(e) => e - .to_string() - .contains(&format!("Table {table_name} already exists")), + Ok(_) => Ok(false), + Err(e) => Ok(e.to_string().contains(&format!("Table {table_name} already exists"))), } }), });