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.
1use orcher::prelude::*;2use anyhow::Result;34#[workflow(name = "resilient_order_processing", version = "1.0.0")]5pub async fn resilient_order_processing(6 ctx: WorkflowContext,7 order: OrderData,8) -> Result<ProcessingResult> {9 let mut results = ProcessingResult::default();1011 // Try primary payment processor12 let payment_handle = ctx13 .start_child_workflow("process_payment", order.clone())14 .await?;1516 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);2425 // Fallback to secondary processor26 let fallback_handle = ctx27 .start_child_workflow("process_payment_fallback", order.clone())28 .await?;2930 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 }4243 // Continue with fulfillment even if payment had issues44 if results.payment.is_some() {45 let fulfillment_handle = ctx46 .start_child_workflow("fulfillment_workflow", order.id.clone())47 .await?;4849 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 }5758 results.success = results.payment.is_some() && results.fulfillment.is_some();5960 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.
The snippets below show the shape of a recursive tree walk — they are conceptual pseudocode, not a copy-paste API. The client type is Client (not OrcherClient); per-workflow status is read through a workflow handle (client.get_workflow(id) / getWorkflowHandle({ workflowId }) / get_workflow_handle(id), then handle.status()); and the SDK does not currently expose a parent's child-workflow IDs for automatic recursion — track child IDs yourself (return them from the parent, or record them in your own store) to walk the tree.
1use orcher::client::OrcherClient;2use anyhow::Result;34async fn monitor_workflow_tree(parent_id: &str) -> Result<()> {5 let client = OrcherClient::new("localhost:50051").await?;67 // Get parent workflow status8 let parent_status = client9 .get_workflow_status(parent_id)10 .await?;1112 println!("Parent Workflow: {}", parent_id);13 println!(" State: {}", parent_status.state);14 println!(" Started: {}", parent_status.started_at);1516 // Query all child workflows17 if let Some(child_ids) = parent_status.child_workflow_ids {18 println!("\nChild Workflows: {}", child_ids.len());1920 for child_id in child_ids {21 let child_status = client.get_workflow_status(&child_id).await?;2223 println!(" └─ Child: {}", child_id);24 println!(" State: {}", child_status.state);25 println!(" Started: {}", child_status.started_at);2627 // Check for grandchildren28 if let Some(grandchild_ids) = child_status.child_workflow_ids {29 println!(" Grandchildren: {}", grandchild_ids.len());3031 for grandchild_id in grandchild_ids {32 let grandchild_status = client33 .get_workflow_status(&grandchild_id)34 .await?;3536 println!(" └─ Grandchild: {}", grandchild_id);37 println!(" State: {}", grandchild_status.state);38 }39 }40 }41 }4243 Ok(())44}