Skip to content

Commit 40329db

Browse files
committed
Log errors
1 parent c301972 commit 40329db

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

src/api/Elastic.Documentation.Api.Infrastructure/Adapters/AskAi/StreamTransformerBase.cs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,46 @@ private async Task ProcessPipeAsync(PipeReader reader, PipeWriter writer, Cancel
5050
{
5151
await ProcessStreamAsync(reader, writer, cancellationToken);
5252
}
53+
catch (OperationCanceledException ex)
54+
{
55+
// Cancellation is expected and not an error - log as debug
56+
Logger.LogDebug("Stream processing was cancelled.");
57+
try
58+
{
59+
await writer.CompleteAsync(ex);
60+
await reader.CompleteAsync(ex);
61+
}
62+
catch (Exception completeEx)
63+
{
64+
Logger.LogError(completeEx, "Error completing pipe after cancellation");
65+
}
66+
return;
67+
}
5368
catch (Exception ex)
5469
{
5570
Logger.LogError(ex, "Error transforming stream. Stream processing will be terminated.");
56-
await writer.CompleteAsync(ex);
57-
await reader.CompleteAsync(ex);
71+
try
72+
{
73+
await writer.CompleteAsync(ex);
74+
await reader.CompleteAsync(ex);
75+
}
76+
catch (Exception completeEx)
77+
{
78+
Logger.LogError(completeEx, "Error completing pipe after transformation error");
79+
}
5880
return;
5981
}
6082

61-
await writer.CompleteAsync();
62-
await reader.CompleteAsync();
83+
// Normal completion - ensure cleanup happens
84+
try
85+
{
86+
await writer.CompleteAsync();
87+
await reader.CompleteAsync();
88+
}
89+
catch (Exception ex)
90+
{
91+
Logger.LogError(ex, "Error completing pipe after successful transformation");
92+
}
6393
}
6494

6595
/// <summary>

0 commit comments

Comments
 (0)