Guides

Error Handling & Monitoring


Error Handling Strategies

When a child workflow fails, the error propagates to the parent's await call on the child handle. Rather than letting this crash the parent, you should catch child failures and decide how to proceed — retry with different parameters, fall back to an alternative service, or collect partial results and continue. This is especially important in multi-child patterns where one failure shouldn't abort the entire operation.

Parent Workflow
spawn children
Child A
✓ success
Child B
✗ failed
Child C
✓ success
error caught in parent
Retry
Different params
Fallback
Alternative service
Partial
Continue without
1
use orcher::prelude::*;
2
use anyhow::Result;
3
4
#[workflow(name = "resilient_order_processing", version = "1.0.0")]
5
pub async fn resilient_order_processing(
6
ctx: WorkflowContext,
7
order: OrderData,
8
) -> Result<ProcessingResult> {
9
let mut results = ProcessingResult::default();
10
11
// Try primary payment processor
12
let payment_handle = ctx
13
.start_child_workflow("process_payment", order.clone())
14
.await?;
15
16
match payment_handle.result::<PaymentResult>().await {
17
Ok(result) => {
18
results.payment = Some(result);
19
}
20
// Re-throw the suspend signal — never treat it as a child failure.
21
Err(e) if e.is_suspend() => return Err(e.into()),
22
Err(e) => {
23
eprintln!("Primary payment failed: {}", e);
24
25
// Fallback to secondary processor
26
let fallback_handle = ctx
27
.start_child_workflow("process_payment_fallback", order.clone())
28
.await?;
29
30
match fallback_handle.result::<PaymentResult>().await {
31
Ok(result) => {
32
results.payment = Some(result);
33
}
34
Err(e) if e.is_suspend() => return Err(e.into()),
35
Err(e) => {
36
eprintln!("Fallback payment also failed: {}", e);
37
results.errors.push(format!("Payment failed: {}", e));
38
}
39
}
40
}
41
}
42
43
// Continue with fulfillment even if payment had issues
44
if results.payment.is_some() {
45
let fulfillment_handle = ctx
46
.start_child_workflow("fulfillment_workflow", order.id.clone())
47
.await?;
48
49
match fulfillment_handle.result::<FulfillmentResult>().await {
50
Ok(result) => results.fulfillment = Some(result),
51
Err(e) if e.is_suspend() => return Err(e.into()),
52
Err(e) => {
53
results.errors.push(format!("Fulfillment failed: {}", e));
54
}
55
}
56
}
57
58
results.success = results.payment.is_some() && results.fulfillment.is_some();
59
60
Ok(results)
61
}

Monitoring Parent-Child Hierarchies

When debugging production issues, you want to see the full execution tree — which children a parent spawned, their current status, and whether any grandchildren are stuck.

1
use orcher::client::OrcherClient;
2
use anyhow::Result;
3
4
async fn monitor_workflow_tree(parent_id: &str) -> Result<()> {
5
let client = OrcherClient::new("localhost:50051").await?;
6
7
// Get parent workflow status
8
let parent_status = client
9
.get_workflow_status(parent_id)
10
.await?;
11
12
println!("Parent Workflow: {}", parent_id);
13
println!(" State: {}", parent_status.state);
14
println!(" Started: {}", parent_status.started_at);
15
16
// Query all child workflows
17
if let Some(child_ids) = parent_status.child_workflow_ids {
18
println!("\nChild Workflows: {}", child_ids.len());
19
20
for child_id in child_ids {
21
let child_status = client.get_workflow_status(&child_id).await?;
22
23
println!(" └─ Child: {}", child_id);
24
println!(" State: {}", child_status.state);
25
println!(" Started: {}", child_status.started_at);
26
27
// Check for grandchildren
28
if let Some(grandchild_ids) = child_status.child_workflow_ids {
29
println!(" Grandchildren: {}", grandchild_ids.len());
30
31
for grandchild_id in grandchild_ids {
32
let grandchild_status = client
33
.get_workflow_status(&grandchild_id)
34
.await?;
35
36
println!(" └─ Grandchild: {}", grandchild_id);
37
println!(" State: {}", grandchild_status.state);
38
}
39
}
40
}
41
}
42
43
Ok(())
44
}

Next Steps