Skip to content

Add OperationCanceledException exceptions automatically #9362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 3, 2023

Conversation

gewarren
Copy link
Contributor

@gewarren gewarren commented Oct 3, 2023

Replaces #8776, which had too many conflicts.

@ghost ghost assigned gewarren Oct 3, 2023
@ghost ghost added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 3, 2023
@ghost
Copy link

ghost commented Oct 3, 2023

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@learn-build-service-prod

This comment was marked as outdated.

@gewarren
Copy link
Contributor Author

gewarren commented Oct 3, 2023

@stephentoub If the methods actually throw a TaskCanceledException, I guess it's still okay to catch OperationCanceledException when you await?

@learn-build-service-prod

This comment was marked as outdated.

@learn-build-service-prod

This comment was marked as outdated.

@stephentoub
Copy link
Member

stephentoub commented Oct 3, 2023

@stephentoub If the methods actually throw a TaskCanceledException, I guess it's still okay to catch OperationCanceledException when you await?

Yes, in fact we want folks to catch OperationCanceledException and not TaskCanceledException. From my perspective, our introducing TaskCanceledException was a well-intentioned mistake. The idea was that it would be an OperationCanceledException that would carry a little more information (the Task that was canceled) if necessary, but that additional information is basically never useful or needed, and it's often not even possible to provide, yet because APIs were throwing it, developers started writing catch blocks for it, which then made it a breaking change for the implementation throwing it to be tweaked in such a way that the base OperationCanceledException was being thrown. We should probably introduce an analyzer to warn people off from catching TaskCanceledException, and maybe even obsolete it (though that's drastic).

@learn-build-service-prod

This comment was marked as outdated.

Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM @gewarren

Let's :shipit:

@BillWagner
Copy link
Member

Based on @stephentoub 's comment, I checked our conceptual and samples repos.

In conceptual docs, I found 138 instances of TaskCanceledException. In our samples, I found 101 instances. Should we update the relevant catch clauses, and the text describing them to catch OperationCanceledException instead?

@gewarren
Copy link
Contributor Author

gewarren commented Oct 3, 2023

In conceptual docs, I found 138 instances of TaskCanceledException. In our samples, I found 101 instances. Should we update the relevant catch clauses, and the text describing them to catch OperationCanceledException instead?

@BillWagner I'd say yes!

@stephentoub
Copy link
Member

Yes, please and thank you.

@learn-build-service-prod
Copy link

Learn Build status updates of commit 52f0fdd:

✅ Validation status: passed

File Status Preview URL Details
xml/Microsoft.Extensions.Caching.Distributed/DistributedCacheExtensions.xml ✅Succeeded View
xml/Microsoft.Extensions.Caching.Distributed/IDistributedCache.xml ✅Succeeded View
xml/Microsoft.Extensions.Caching.Distributed/MemoryDistributedCache.xml ✅Succeeded View
xml/Microsoft.Extensions.Caching.Redis/RedisCache.xml ✅Succeeded View
xml/Microsoft.Extensions.Caching.SqlServer/SqlServerCache.xml ✅Succeeded View
xml/Microsoft.Extensions.Caching.StackExchangeRedis/RedisCache.xml ✅Succeeded View
xml/Microsoft.Extensions.Diagnostics.HealthChecks/HealthCheckService.xml ✅Succeeded View
xml/Microsoft.Extensions.Diagnostics.HealthChecks/IHealthCheck.xml ✅Succeeded View
xml/Microsoft.Extensions.Diagnostics.HealthChecks/IHealthCheckPublisher.xml ✅Succeeded View
xml/Microsoft.Extensions.Diagnostics.ResourceMonitoring/IResourceUtilizationPublisher.xml ✅Succeeded View
xml/Microsoft.Extensions.Hosting.Internal/ConsoleLifetime.xml ✅Succeeded View
xml/Microsoft.Extensions.Hosting.Systemd/SystemdLifetime.xml ✅Succeeded View
xml/Microsoft.Extensions.Hosting.Testing/FakeHost.xml ✅Succeeded View
xml/Microsoft.Extensions.Hosting.Testing/HostingFakesExtensions.xml ✅Succeeded View
xml/Microsoft.Extensions.Hosting.WindowsServices/WindowsServiceLifetime.xml ✅Succeeded View
xml/Microsoft.Extensions.Hosting/BackgroundService.xml ✅Succeeded View
xml/Microsoft.Extensions.Hosting/HostingAbstractionsHostBuilderExtensions.xml ✅Succeeded View
xml/Microsoft.Extensions.Hosting/HostingAbstractionsHostExtensions.xml ✅Succeeded View
xml/Microsoft.Extensions.Hosting/HostingHostBuilderExtensions.xml ✅Succeeded View
xml/Microsoft.Extensions.Hosting/IHost.xml ✅Succeeded View
xml/Microsoft.Extensions.Hosting/IHostedLifecycleService.xml ✅Succeeded View
xml/Microsoft.Extensions.Hosting/IHostedService.xml ✅Succeeded View
xml/Microsoft.Extensions.Hosting/IHostLifetime.xml ✅Succeeded View
xml/Microsoft.Extensions.Http.AutoClient/AutoClientHttpError.xml ✅Succeeded View
xml/Microsoft.Extensions.Http.Logging/IHttpClientAsyncLogger.xml ✅Succeeded View

This comment lists only the first 25 files in the pull request.
For more details, please refer to the build report.

For any questions, please:

@learn-build-service-prod
Copy link

Learn Build status updates of commit 55eac5d:

✅ Validation status: passed

File Status Preview URL Details
xml/Microsoft.Extensions.Caching.Distributed/DistributedCacheExtensions.xml ✅Succeeded View
xml/Microsoft.Extensions.Caching.Distributed/IDistributedCache.xml ✅Succeeded View
xml/Microsoft.Extensions.Caching.Distributed/MemoryDistributedCache.xml ✅Succeeded View
xml/Microsoft.Extensions.Caching.Redis/RedisCache.xml ✅Succeeded View
xml/Microsoft.Extensions.Caching.SqlServer/SqlServerCache.xml ✅Succeeded View
xml/Microsoft.Extensions.Caching.StackExchangeRedis/RedisCache.xml ✅Succeeded View
xml/Microsoft.Extensions.Diagnostics.HealthChecks/HealthCheckService.xml ✅Succeeded View
xml/Microsoft.Extensions.Diagnostics.HealthChecks/IHealthCheck.xml ✅Succeeded View
xml/Microsoft.Extensions.Diagnostics.HealthChecks/IHealthCheckPublisher.xml ✅Succeeded View
xml/Microsoft.Extensions.Diagnostics.ResourceMonitoring/IResourceUtilizationPublisher.xml ✅Succeeded View
xml/Microsoft.Extensions.Hosting.Internal/ConsoleLifetime.xml ✅Succeeded View
xml/Microsoft.Extensions.Hosting.Systemd/SystemdLifetime.xml ✅Succeeded View
xml/Microsoft.Extensions.Hosting.Testing/FakeHost.xml ✅Succeeded View
xml/Microsoft.Extensions.Hosting.Testing/HostingFakesExtensions.xml ✅Succeeded View
xml/Microsoft.Extensions.Hosting.WindowsServices/WindowsServiceLifetime.xml ✅Succeeded View
xml/Microsoft.Extensions.Hosting/BackgroundService.xml ✅Succeeded View
xml/Microsoft.Extensions.Hosting/HostingAbstractionsHostBuilderExtensions.xml ✅Succeeded View
xml/Microsoft.Extensions.Hosting/HostingAbstractionsHostExtensions.xml ✅Succeeded View
xml/Microsoft.Extensions.Hosting/HostingHostBuilderExtensions.xml ✅Succeeded View
xml/Microsoft.Extensions.Hosting/IHost.xml ✅Succeeded View
xml/Microsoft.Extensions.Hosting/IHostedLifecycleService.xml ✅Succeeded View
xml/Microsoft.Extensions.Hosting/IHostedService.xml ✅Succeeded View
xml/Microsoft.Extensions.Hosting/IHostLifetime.xml ✅Succeeded View
xml/Microsoft.Extensions.Http.AutoClient/AutoClientHttpError.xml ✅Succeeded View
xml/Microsoft.Extensions.Http.Logging/IHttpClientAsyncLogger.xml ✅Succeeded View

This comment lists only the first 25 files in the pull request.
For more details, please refer to the build report.

For any questions, please:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants