Add error handling to additional workflow samples with agents

Co-authored-by: lokitoth <6936551+lokitoth@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-17 15:38:19 +00:00
committed by Jacob Alber
Unverified
parent 66111a5705
commit ddf1d63854
4 changed files with 67 additions and 12 deletions
@@ -64,9 +64,23 @@ public static class Program
await using StreamingRun run = await InProcessExecution.StreamAsync(workflow, input: "What is temperature?");
await foreach (WorkflowEvent evt in run.WatchStreamAsync())
{
if (evt is WorkflowOutputEvent output)
switch (evt)
{
Console.WriteLine($"Workflow completed with results:\n{output.Data}");
case WorkflowOutputEvent output:
Console.WriteLine($"Workflow completed with results:\n{output.Data}");
break;
case ExecutorFailedEvent failureEvent:
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Executor failed [{failureEvent.ExecutorId}]: {failureEvent.Data?.Message ?? "Unknown error"}");
Console.ResetColor();
break;
case WorkflowErrorEvent errorEvent:
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Workflow error: {errorEvent.Exception?.Message ?? "Unknown error"}");
Console.ResetColor();
throw errorEvent.Exception ?? new InvalidOperationException("Workflow encountered an error.");
}
}
}
@@ -68,9 +68,23 @@ public static class Program
await run.TrySendMessageAsync(new TurnToken(emitEvents: true));
await foreach (WorkflowEvent evt in run.WatchStreamAsync())
{
if (evt is WorkflowOutputEvent outputEvent)
switch (evt)
{
Console.WriteLine($"{outputEvent}");
case WorkflowOutputEvent outputEvent:
Console.WriteLine($"{outputEvent}");
break;
case ExecutorFailedEvent failureEvent:
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Executor failed [{failureEvent.ExecutorId}]: {failureEvent.Data?.Message ?? "Unknown error"}");
Console.ResetColor();
break;
case WorkflowErrorEvent errorEvent:
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Workflow error: {errorEvent.Exception?.Message ?? "Unknown error"}");
Console.ResetColor();
throw errorEvent.Exception ?? new InvalidOperationException("Workflow encountered an error.");
}
}
}
@@ -84,9 +84,23 @@ public static class Program
await run.TrySendMessageAsync(new TurnToken(emitEvents: true));
await foreach (WorkflowEvent evt in run.WatchStreamAsync())
{
if (evt is WorkflowOutputEvent outputEvent)
switch (evt)
{
Console.WriteLine($"{outputEvent}");
case WorkflowOutputEvent outputEvent:
Console.WriteLine($"{outputEvent}");
break;
case ExecutorFailedEvent failureEvent:
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Executor failed [{failureEvent.ExecutorId}]: {failureEvent.Data?.Message ?? "Unknown error"}");
Console.ResetColor();
break;
case WorkflowErrorEvent errorEvent:
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Workflow error: {errorEvent.Exception?.Message ?? "Unknown error"}");
Console.ResetColor();
throw errorEvent.Exception ?? new InvalidOperationException("Workflow encountered an error.");
}
}
}
@@ -92,14 +92,27 @@ public static class Program
await run.TrySendMessageAsync(new TurnToken(emitEvents: true));
await foreach (WorkflowEvent evt in run.WatchStreamAsync())
{
if (evt is WorkflowOutputEvent outputEvent)
switch (evt)
{
Console.WriteLine($"{outputEvent}");
}
case WorkflowOutputEvent outputEvent:
Console.WriteLine($"{outputEvent}");
break;
if (evt is DatabaseEvent databaseEvent)
{
Console.WriteLine($"{databaseEvent}");
case DatabaseEvent databaseEvent:
Console.WriteLine($"{databaseEvent}");
break;
case ExecutorFailedEvent failureEvent:
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Executor failed [{failureEvent.ExecutorId}]: {failureEvent.Data?.Message ?? "Unknown error"}");
Console.ResetColor();
break;
case WorkflowErrorEvent errorEvent:
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Workflow error: {errorEvent.Exception?.Message ?? "Unknown error"}");
Console.ResetColor();
throw errorEvent.Exception ?? new InvalidOperationException("Workflow encountered an error.");
}
}
}