Skip to content

Commit 49569b4

Browse files
fix: address remaining code review feedback
- Narrow generic catch clauses in .NET command/elicitation handlers with 'when (ex is not OperationCanceledException)' filter - Remove redundant null-conditional (val?.ToString -> val.ToString) in SelectAsync and InputAsync switch expressions - Add explanatory comments to Python empty except blocks
1 parent f8f13fa commit 49569b4

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

dotnet/src/Session.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,10 @@ await handler(new CommandContext
698698
});
699699
await Rpc.Commands.HandlePendingCommandAsync(requestId);
700700
}
701-
catch (Exception error)
701+
catch (Exception error) when (error is not OperationCanceledException)
702702
{
703+
// User handler can throw any exception — report the error back to the server
704+
// so the pending command doesn't hang.
703705
var message = error.Message;
704706
try
705707
{
@@ -730,9 +732,9 @@ private async Task HandleElicitationRequestAsync(ElicitationRequest request, str
730732
Content = result.Content
731733
});
732734
}
733-
catch (Exception)
735+
catch (Exception ex) when (ex is not OperationCanceledException)
734736
{
735-
// Handler failed — attempt to cancel so the request doesn't hang
737+
// User handler can throw any exception — attempt to cancel so the request doesn't hang.
736738
try
737739
{
738740
await Rpc.Ui.HandlePendingElicitationAsync(requestId, new SessionUiHandlePendingElicitationRequestResult
@@ -827,7 +829,7 @@ public async Task<bool> ConfirmAsync(string message, CancellationToken cancellat
827829
{
828830
string s => s,
829831
JsonElement { ValueKind: JsonValueKind.String } je => je.GetString(),
830-
_ => val?.ToString()
832+
_ => val.ToString()
831833
};
832834
}
833835
return null;
@@ -859,7 +861,7 @@ public async Task<bool> ConfirmAsync(string message, CancellationToken cancellat
859861
{
860862
string s => s,
861863
JsonElement { ValueKind: JsonValueKind.String } je => je.GetString(),
862-
_ => val?.ToString()
864+
_ => val.ToString()
863865
};
864866
}
865867
return null;

python/copilot/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,11 +2265,11 @@ def terminate(self):
22652265
try:
22662266
self.stdin.close()
22672267
except OSError:
2268-
pass
2268+
pass # Safe to ignore — socket may already be closed
22692269
try:
22702270
self._socket.close()
22712271
except OSError:
2272-
pass
2272+
pass # Safe to ignore — socket may already be closed
22732273

22742274
def kill(self):
22752275
self.terminate()

0 commit comments

Comments
 (0)