diff --git a/dotnet/samples/03-workflows/Agents/FoundryAgent/Program.cs b/dotnet/samples/03-workflows/Agents/FoundryAgent/Program.cs index cab2e0162d..91d52398f9 100644 --- a/dotnet/samples/03-workflows/Agents/FoundryAgent/Program.cs +++ b/dotnet/samples/03-workflows/Agents/FoundryAgent/Program.cs @@ -53,6 +53,18 @@ private static async Task Main() { Console.WriteLine($"{executorComplete.ExecutorId}: {executorComplete.Data}"); } + else if (evt is WorkflowErrorEvent workflowError) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + } + else if (evt is ExecutorFailedEvent executorFailed) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + } } } finally diff --git a/dotnet/samples/03-workflows/Agents/GroupChatToolApproval/Program.cs b/dotnet/samples/03-workflows/Agents/GroupChatToolApproval/Program.cs index 0b6b821f9f..c6d41b031b 100644 --- a/dotnet/samples/03-workflows/Agents/GroupChatToolApproval/Program.cs +++ b/dotnet/samples/03-workflows/Agents/GroupChatToolApproval/Program.cs @@ -134,6 +134,18 @@ private static async Task Main() break; } + + case WorkflowErrorEvent workflowError: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + break; + + case ExecutorFailedEvent executorFailed: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + break; } } diff --git a/dotnet/samples/03-workflows/Checkpoint/CheckpointAndRehydrate/Program.cs b/dotnet/samples/03-workflows/Checkpoint/CheckpointAndRehydrate/Program.cs index 7bc5621fbe..d8d88aefcb 100644 --- a/dotnet/samples/03-workflows/Checkpoint/CheckpointAndRehydrate/Program.cs +++ b/dotnet/samples/03-workflows/Checkpoint/CheckpointAndRehydrate/Program.cs @@ -37,26 +37,41 @@ private static async Task Main() await foreach (WorkflowEvent evt in checkpointedRun.WatchStreamAsync()) { - if (evt is ExecutorCompletedEvent executorCompletedEvt) + switch (evt) { - Console.WriteLine($"* Executor {executorCompletedEvt.ExecutorId} completed."); - } + case ExecutorCompletedEvent executorCompletedEvt: + Console.WriteLine($"* Executor {executorCompletedEvt.ExecutorId} completed."); + break; - if (evt is SuperStepCompletedEvent superStepCompletedEvt) - { - // Checkpoints are automatically created at the end of each super step when a - // checkpoint manager is provided. You can store the checkpoint info for later use. - CheckpointInfo? checkpoint = superStepCompletedEvt.CompletionInfo!.Checkpoint; - if (checkpoint is not null) + case SuperStepCompletedEvent superStepCompletedEvt: { - checkpoints.Add(checkpoint); - Console.WriteLine($"** Checkpoint created at step {checkpoints.Count}."); + // Checkpoints are automatically created at the end of each super step when a + // checkpoint manager is provided. You can store the checkpoint info for later use. + CheckpointInfo? checkpoint = superStepCompletedEvt.CompletionInfo!.Checkpoint; + if (checkpoint is not null) + { + checkpoints.Add(checkpoint); + Console.WriteLine($"** Checkpoint created at step {checkpoints.Count}."); + } + + break; } - } - if (evt is WorkflowOutputEvent outputEvent) - { - Console.WriteLine($"Workflow completed with result: {outputEvent.Data}"); + case WorkflowOutputEvent outputEvent: + Console.WriteLine($"Workflow completed with result: {outputEvent.Data}"); + break; + + case WorkflowErrorEvent workflowError: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + break; + + case ExecutorFailedEvent executorFailed: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + break; } } @@ -77,14 +92,27 @@ private static async Task Main() await foreach (WorkflowEvent evt in newCheckpointedRun.WatchStreamAsync()) { - if (evt is ExecutorCompletedEvent executorCompletedEvt) + switch (evt) { - Console.WriteLine($"* Executor {executorCompletedEvt.ExecutorId} completed."); - } + case ExecutorCompletedEvent executorCompletedEvt: + Console.WriteLine($"* Executor {executorCompletedEvt.ExecutorId} completed."); + break; - if (evt is WorkflowOutputEvent workflowOutputEvt) - { - Console.WriteLine($"Workflow completed with result: {workflowOutputEvt.Data}"); + case WorkflowOutputEvent workflowOutputEvt: + Console.WriteLine($"Workflow completed with result: {workflowOutputEvt.Data}"); + break; + + case WorkflowErrorEvent workflowError: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + break; + + case ExecutorFailedEvent executorFailed: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + break; } } } diff --git a/dotnet/samples/03-workflows/Checkpoint/CheckpointAndResume/Program.cs b/dotnet/samples/03-workflows/Checkpoint/CheckpointAndResume/Program.cs index 07be486620..caa594ae08 100644 --- a/dotnet/samples/03-workflows/Checkpoint/CheckpointAndResume/Program.cs +++ b/dotnet/samples/03-workflows/Checkpoint/CheckpointAndResume/Program.cs @@ -34,26 +34,41 @@ private static async Task Main() await using StreamingRun checkpointedRun = await InProcessExecution.RunStreamingAsync(workflow, NumberSignal.Init, checkpointManager); await foreach (WorkflowEvent evt in checkpointedRun.WatchStreamAsync()) { - if (evt is ExecutorCompletedEvent executorCompletedEvt) + switch (evt) { - Console.WriteLine($"* Executor {executorCompletedEvt.ExecutorId} completed."); - } + case ExecutorCompletedEvent executorCompletedEvt: + Console.WriteLine($"* Executor {executorCompletedEvt.ExecutorId} completed."); + break; - if (evt is SuperStepCompletedEvent superStepCompletedEvt) - { - // Checkpoints are automatically created at the end of each super step when a - // checkpoint manager is provided. You can store the checkpoint info for later use. - CheckpointInfo? checkpoint = superStepCompletedEvt.CompletionInfo!.Checkpoint; - if (checkpoint is not null) + case SuperStepCompletedEvent superStepCompletedEvt: { - checkpoints.Add(checkpoint); - Console.WriteLine($"** Checkpoint created at step {checkpoints.Count}."); + // Checkpoints are automatically created at the end of each super step when a + // checkpoint manager is provided. You can store the checkpoint info for later use. + CheckpointInfo? checkpoint = superStepCompletedEvt.CompletionInfo!.Checkpoint; + if (checkpoint is not null) + { + checkpoints.Add(checkpoint); + Console.WriteLine($"** Checkpoint created at step {checkpoints.Count}."); + } + + break; } - } - if (evt is WorkflowOutputEvent workflowOutputEvt) - { - Console.WriteLine($"Workflow completed with result: {workflowOutputEvt.Data}"); + case WorkflowOutputEvent outputEvent: + Console.WriteLine($"Workflow completed with result: {outputEvent.Data}"); + break; + + case WorkflowErrorEvent workflowError: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + break; + + case ExecutorFailedEvent executorFailed: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + break; } } @@ -71,14 +86,27 @@ private static async Task Main() await checkpointedRun.RestoreCheckpointAsync(savedCheckpoint, CancellationToken.None); await foreach (WorkflowEvent evt in checkpointedRun.WatchStreamAsync()) { - if (evt is ExecutorCompletedEvent executorCompletedEvt) + switch (evt) { - Console.WriteLine($"* Executor {executorCompletedEvt.ExecutorId} completed."); - } + case ExecutorCompletedEvent executorCompletedEvt: + Console.WriteLine($"* Executor {executorCompletedEvt.ExecutorId} completed."); + break; - if (evt is WorkflowOutputEvent workflowOutputEvt) - { - Console.WriteLine($"Workflow completed with result: {workflowOutputEvt.Data}"); + case WorkflowOutputEvent workflowOutputEvt: + Console.WriteLine($"Workflow completed with result: {workflowOutputEvt.Data}"); + break; + + case WorkflowErrorEvent workflowError: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + break; + + case ExecutorFailedEvent executorFailed: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + break; } } } diff --git a/dotnet/samples/03-workflows/Checkpoint/CheckpointWithHumanInTheLoop/Program.cs b/dotnet/samples/03-workflows/Checkpoint/CheckpointWithHumanInTheLoop/Program.cs index 56b4da9911..4dcf097468 100644 --- a/dotnet/samples/03-workflows/Checkpoint/CheckpointWithHumanInTheLoop/Program.cs +++ b/dotnet/samples/03-workflows/Checkpoint/CheckpointWithHumanInTheLoop/Program.cs @@ -62,6 +62,16 @@ private static async Task Main() case WorkflowOutputEvent workflowOutputEvt: Console.WriteLine($"Workflow completed with result: {workflowOutputEvt.Data}"); break; + case WorkflowErrorEvent workflowError: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + break; + case ExecutorFailedEvent executorFailed: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + break; } } @@ -92,6 +102,16 @@ private static async Task Main() case WorkflowOutputEvent workflowOutputEvt: Console.WriteLine($"Workflow completed with result: {workflowOutputEvt.Data}"); break; + case WorkflowErrorEvent workflowError: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + break; + case ExecutorFailedEvent executorFailed: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + break; } } } diff --git a/dotnet/samples/03-workflows/Concurrent/MapReduce/Program.cs b/dotnet/samples/03-workflows/Concurrent/MapReduce/Program.cs index 9049bde982..5d7ab5b688 100644 --- a/dotnet/samples/03-workflows/Concurrent/MapReduce/Program.cs +++ b/dotnet/samples/03-workflows/Concurrent/MapReduce/Program.cs @@ -119,6 +119,18 @@ private static async Task RunWorkflowAsync(Workflow workflow) } } } + else if (evt is WorkflowErrorEvent workflowError) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + } + else if (evt is ExecutorFailedEvent executorFailed) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + } } } } diff --git a/dotnet/samples/03-workflows/ConditionalEdges/01_EdgeCondition/Program.cs b/dotnet/samples/03-workflows/ConditionalEdges/01_EdgeCondition/Program.cs index 370011d80f..57a026b4a5 100644 --- a/dotnet/samples/03-workflows/ConditionalEdges/01_EdgeCondition/Program.cs +++ b/dotnet/samples/03-workflows/ConditionalEdges/01_EdgeCondition/Program.cs @@ -69,6 +69,18 @@ private static async Task Main() { Console.WriteLine($"{outputEvent}"); } + else if (evt is WorkflowErrorEvent workflowError) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + } + else if (evt is ExecutorFailedEvent executorFailed) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + } } } diff --git a/dotnet/samples/03-workflows/ConditionalEdges/02_SwitchCase/Program.cs b/dotnet/samples/03-workflows/ConditionalEdges/02_SwitchCase/Program.cs index 4e85039af8..9b1a8d3d05 100644 --- a/dotnet/samples/03-workflows/ConditionalEdges/02_SwitchCase/Program.cs +++ b/dotnet/samples/03-workflows/ConditionalEdges/02_SwitchCase/Program.cs @@ -85,6 +85,18 @@ private static async Task Main() { Console.WriteLine($"{outputEvent}"); } + else if (evt is WorkflowErrorEvent workflowError) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + } + else if (evt is ExecutorFailedEvent executorFailed) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + } } } diff --git a/dotnet/samples/03-workflows/ConditionalEdges/03_MultiSelection/Program.cs b/dotnet/samples/03-workflows/ConditionalEdges/03_MultiSelection/Program.cs index 3dfb13bf60..d0b1a2a673 100644 --- a/dotnet/samples/03-workflows/ConditionalEdges/03_MultiSelection/Program.cs +++ b/dotnet/samples/03-workflows/ConditionalEdges/03_MultiSelection/Program.cs @@ -93,11 +93,22 @@ private static async Task Main() { Console.WriteLine($"{outputEvent}"); } - - if (evt is DatabaseEvent databaseEvent) + else if (evt is DatabaseEvent databaseEvent) { Console.WriteLine($"{databaseEvent}"); } + else if (evt is WorkflowErrorEvent workflowError) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + } + else if (evt is ExecutorFailedEvent executorFailed) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + } } } diff --git a/dotnet/samples/03-workflows/HumanInTheLoop/HumanInTheLoopBasic/Program.cs b/dotnet/samples/03-workflows/HumanInTheLoop/HumanInTheLoopBasic/Program.cs index 0b85757435..b1ba52bdf0 100644 --- a/dotnet/samples/03-workflows/HumanInTheLoop/HumanInTheLoopBasic/Program.cs +++ b/dotnet/samples/03-workflows/HumanInTheLoop/HumanInTheLoopBasic/Program.cs @@ -42,6 +42,18 @@ private static async Task Main() // The workflow has yielded output Console.WriteLine($"Workflow completed with result: {outputEvt.Data}"); return; + + case WorkflowErrorEvent workflowError: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + return; + + case ExecutorFailedEvent executorFailed: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + return; } } } diff --git a/dotnet/samples/03-workflows/Loop/Program.cs b/dotnet/samples/03-workflows/Loop/Program.cs index dba811d84c..3631eebe32 100644 --- a/dotnet/samples/03-workflows/Loop/Program.cs +++ b/dotnet/samples/03-workflows/Loop/Program.cs @@ -39,6 +39,18 @@ private static async Task Main() { Console.WriteLine($"Result: {outputEvent}"); } + else if (evt is WorkflowErrorEvent workflowError) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + } + else if (evt is ExecutorFailedEvent executorFailed) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + } } } } diff --git a/dotnet/samples/03-workflows/Observability/ApplicationInsights/Program.cs b/dotnet/samples/03-workflows/Observability/ApplicationInsights/Program.cs index a05a5cddf6..3d8d61b8a4 100644 --- a/dotnet/samples/03-workflows/Observability/ApplicationInsights/Program.cs +++ b/dotnet/samples/03-workflows/Observability/ApplicationInsights/Program.cs @@ -67,6 +67,18 @@ private static async Task Main() { Console.WriteLine($"{executorComplete.ExecutorId}: {executorComplete.Data}"); } + else if (evt is WorkflowErrorEvent workflowError) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + } + else if (evt is ExecutorFailedEvent executorFailed) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + } } } } diff --git a/dotnet/samples/03-workflows/Observability/AspireDashboard/Program.cs b/dotnet/samples/03-workflows/Observability/AspireDashboard/Program.cs index 23fcfe5f4e..9e5a396656 100644 --- a/dotnet/samples/03-workflows/Observability/AspireDashboard/Program.cs +++ b/dotnet/samples/03-workflows/Observability/AspireDashboard/Program.cs @@ -69,6 +69,18 @@ private static async Task Main() { Console.WriteLine($"{executorComplete.ExecutorId}: {executorComplete.Data}"); } + else if (evt is WorkflowErrorEvent workflowError) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + } + else if (evt is ExecutorFailedEvent executorFailed) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + } } } } diff --git a/dotnet/samples/03-workflows/SharedStates/Program.cs b/dotnet/samples/03-workflows/SharedStates/Program.cs index ebe3aaeb3b..c8532676e6 100644 --- a/dotnet/samples/03-workflows/SharedStates/Program.cs +++ b/dotnet/samples/03-workflows/SharedStates/Program.cs @@ -39,6 +39,18 @@ private static async Task Main() { Console.WriteLine(outputEvent.Data); } + else if (evt is WorkflowErrorEvent workflowError) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + } + else if (evt is ExecutorFailedEvent executorFailed) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + } } } } diff --git a/dotnet/samples/03-workflows/_StartHere/01_Streaming/Program.cs b/dotnet/samples/03-workflows/_StartHere/01_Streaming/Program.cs index 81ca2f3276..6193d1c8f6 100644 --- a/dotnet/samples/03-workflows/_StartHere/01_Streaming/Program.cs +++ b/dotnet/samples/03-workflows/_StartHere/01_Streaming/Program.cs @@ -35,6 +35,18 @@ private static async Task Main() { Console.WriteLine($"{executorCompleted.ExecutorId}: {executorCompleted.Data}"); } + else if (evt is WorkflowErrorEvent workflowError) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + } + else if (evt is ExecutorFailedEvent executorFailed) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + } } } } diff --git a/dotnet/samples/03-workflows/_StartHere/02_AgentsInWorkflows/Program.cs b/dotnet/samples/03-workflows/_StartHere/02_AgentsInWorkflows/Program.cs index d0bc5d4749..eee12e03ef 100644 --- a/dotnet/samples/03-workflows/_StartHere/02_AgentsInWorkflows/Program.cs +++ b/dotnet/samples/03-workflows/_StartHere/02_AgentsInWorkflows/Program.cs @@ -56,6 +56,18 @@ private static async Task Main() { Console.WriteLine($"{executorComplete.ExecutorId}: {executorComplete.Data}"); } + else if (evt is WorkflowErrorEvent workflowError) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + } + else if (evt is ExecutorFailedEvent executorFailed) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + } } } diff --git a/dotnet/samples/03-workflows/_StartHere/03_AgentWorkflowPatterns/Program.cs b/dotnet/samples/03-workflows/_StartHere/03_AgentWorkflowPatterns/Program.cs index 7e6fb55be7..ddead5023f 100644 --- a/dotnet/samples/03-workflows/_StartHere/03_AgentWorkflowPatterns/Program.cs +++ b/dotnet/samples/03-workflows/_StartHere/03_AgentWorkflowPatterns/Program.cs @@ -111,6 +111,18 @@ static async Task> RunWorkflowAsync(Workflow workflow, List>()!; } + else if (evt is WorkflowErrorEvent workflowError) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + } + else if (evt is ExecutorFailedEvent executorFailed) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + } } return []; diff --git a/dotnet/samples/03-workflows/_StartHere/05_SubWorkflows/Program.cs b/dotnet/samples/03-workflows/_StartHere/05_SubWorkflows/Program.cs index 7f9980e047..05b0db7f0d 100644 --- a/dotnet/samples/03-workflows/_StartHere/05_SubWorkflows/Program.cs +++ b/dotnet/samples/03-workflows/_StartHere/05_SubWorkflows/Program.cs @@ -74,6 +74,18 @@ private static async Task Main() Console.WriteLine($"Final Output: {output.Data}"); Console.ResetColor(); } + else if (evt is WorkflowErrorEvent workflowError) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + } + else if (evt is ExecutorFailedEvent executorFailed) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + } } // Optional: Visualize the workflow structure - Note that sub-workflows are not rendered diff --git a/dotnet/samples/03-workflows/_StartHere/06_MixedWorkflowAgentsAndExecutors/Program.cs b/dotnet/samples/03-workflows/_StartHere/06_MixedWorkflowAgentsAndExecutors/Program.cs index 2359a1f10e..64993b1590 100644 --- a/dotnet/samples/03-workflows/_StartHere/06_MixedWorkflowAgentsAndExecutors/Program.cs +++ b/dotnet/samples/03-workflows/_StartHere/06_MixedWorkflowAgentsAndExecutors/Program.cs @@ -156,6 +156,18 @@ private static async Task ExecuteWorkflowAsync(Workflow workflow, string input) case WorkflowOutputEvent: // Workflow completed - final output already printed by FinalOutputExecutor break; + + case WorkflowErrorEvent workflowError: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + break; + + case ExecutorFailedEvent executorFailed: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + break; } } } diff --git a/dotnet/samples/03-workflows/_StartHere/07_WriterCriticWorkflow/Program.cs b/dotnet/samples/03-workflows/_StartHere/07_WriterCriticWorkflow/Program.cs index 0d8ffbf1cf..4665f09f6f 100644 --- a/dotnet/samples/03-workflows/_StartHere/07_WriterCriticWorkflow/Program.cs +++ b/dotnet/samples/03-workflows/_StartHere/07_WriterCriticWorkflow/Program.cs @@ -115,6 +115,18 @@ private static async Task ExecuteWorkflowAsync(Workflow workflow, string input) Console.WriteLine(); Console.WriteLine(new string('=', 80)); break; + + case WorkflowErrorEvent workflowError: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(workflowError.Exception?.ToString() ?? "Unknown workflow error occurred."); + Console.ResetColor(); + break; + + case ExecutorFailedEvent executorFailed: + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Executor '{executorFailed.ExecutorId}' failed with {(executorFailed.Data == null ? "unknown error" : $"exception {executorFailed.Data}")}."); + Console.ResetColor(); + break; } } }