Skip to content

Commit 674cc87

Browse files
authored
Explicitly check for CTLR+C during exception filter (#1748)
1 parent b767a42 commit 674cc87

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/tooling/Elastic.Documentation.Tooling/Filters/CatchExceptionFilter.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,21 @@ namespace Elastic.Documentation.Tooling.Filters;
1010
public sealed class CatchExceptionFilter(ConsoleAppFilter next, ILogger<CatchExceptionFilter> logger)
1111
: ConsoleAppFilter(next)
1212
{
13+
private bool _cancelKeyPressed;
1314
public override async Task InvokeAsync(ConsoleAppContext context, Cancel cancellationToken)
1415
{
16+
Console.CancelKeyPress += (sender, e) =>
17+
{
18+
logger.LogInformation("Received CTRL+C cancelling");
19+
_cancelKeyPressed = true;
20+
};
1521
try
1622
{
1723
await Next.InvokeAsync(context, cancellationToken);
1824
}
1925
catch (Exception ex)
2026
{
21-
if (ex is OperationCanceledException)
27+
if (ex is OperationCanceledException && cancellationToken.IsCancellationRequested && _cancelKeyPressed)
2228
{
2329
logger.LogInformation("Cancellation requested, exiting.");
2430
return;

0 commit comments

Comments
 (0)