fix macros more

This commit is contained in:
Christian Schwarz
2025-07-11 13:03:22 +02:00
parent 9aeee51bf3
commit ac5279e600
4 changed files with 16 additions and 15 deletions

View File

@@ -45,7 +45,7 @@ pub enum FailpointAction {
/// Sleep for a specified duration in milliseconds
Sleep(u64),
/// Return a value (for failpoints that support it)
Return(String),
Return(Option<String>),
/// Exit the process immediately
Exit,
}
@@ -59,7 +59,7 @@ pub enum FailpointResult {
/// Continue normal execution
Continue,
/// Return early with a value
Return(String),
Return(Option<String>),
/// Cancelled by cancellation token
Cancelled,
}
@@ -264,7 +264,7 @@ pub async fn failpoint_with_cancellation(
result
}
FailpointAction::Return(value) => {
tracing::info!("Failpoint {} returning: {}", name, value);
tracing::info!("Failpoint {} returning: {:?}", name, value);
FailpointResult::Return(value)
}
FailpointAction::Exit => {
@@ -280,12 +280,12 @@ fn parse_action(actions: &str) -> Result<FailpointAction> {
"off" => Ok(FailpointAction::Off),
"pause" => Ok(FailpointAction::Pause),
"exit" => Ok(FailpointAction::Exit),
"return" => Ok(FailpointAction::Return(String::new())),
"return" => Ok(FailpointAction::Return(None)),
_ => {
// Try to parse return(value) format
if let Some(captures) = regex::Regex::new(r"^return\(([^)]*)\)$")?.captures(actions) {
let value = captures.get(1).unwrap().as_str().to_string();
Ok(FailpointAction::Return(value))
Ok(FailpointAction::Return(Some(value)))
}
// Try to parse sleep(millis) format
else if let Some(captures) = regex::Regex::new(r"^sleep\((\d+)\)$")?.captures(actions) {

View File

@@ -7,10 +7,11 @@ macro_rules! fail_point {
if cfg!(feature = "testing") {
match $crate::failpoint($name, None).await {
$crate::FailpointResult::Continue => {},
$crate::FailpointResult::Return(value) => {
// For compatibility with fail crate, we need to handle the return value
// This will be used in closures like |x| x pattern
return Ok(value.parse().unwrap_or_default());
$crate::FailpointResult::Return(None) => {
return;
},
$crate::FailpointResult::Return(Some(value)) => {
panic!("failpoint was configured with return(X) but Rust code does not pass a closure to map X to a return value");
},
$crate::FailpointResult::Cancelled => {},
}
@@ -22,7 +23,7 @@ macro_rules! fail_point {
$crate::FailpointResult::Continue => {},
$crate::FailpointResult::Return(value) => {
let closure = $closure;
return closure(value.as_str());
return closure(value);
},
$crate::FailpointResult::Cancelled => {},
}