elastic / elasticsearch-net

This strongly-typed, client library enables working with Elasticsearch. It is the official client maintained and supported by Elastic.
https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/index.html
Apache License 2.0
11 stars 1.15k forks source link

Wrapping of TaskCanceledException #6074

Open jhouben98 opened 2 years ago

jhouben98 commented 2 years ago

Is your feature request related to a problem? Please describe. When a request is cancelled, an UnexpectedElasticsearchClientException with an inner TaskCanceledException is thrown. This is very annoying because it's not catched with catch (OperationCanceledException).

Describe the solution you'd like TaskCanceledException / OperationCanceledException is automatically unwrapped / not wrapped before it's thrown.

Describe alternatives you've considered I'm currently using this: catch (UnexpectedElasticsearchClientException ex) when (ex.InnerException is OperationCanceledException)

Additional context TaskCanceledException is derived from OperationCanceledException.

It's also not recognized by dependent libraries (for example: BackgroundService of .NET Core / Worker Service), meaning they will see an error instead of cancellation when the Elasticsearch Exception is thrown.

stevejgordon commented 2 years ago

@jhouben98 This is a fair point. I'll dig into any historical reasons for this. While it's not something we could change in v7 as it would be breaking behaviour, I'd like to review this in the v8 timeframe.

bt-Knodel commented 2 weeks ago

Would love to see this implemented. Wrapping exceptions like OperationCancelledException/TaskCancelledException in ElasticSearchException leads to a lot of unexpected error reporting when implementing a cancellable search or auto-search feature. Not to mention the unnecessary boilerplate to convert back in consuming applications using the library.