Add ObserveException extension methods for Task and Task<T> - #92
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces ObserveException() extension methods on Task and Task<T> to explicitly observe (and thereby suppress) unobserved task exceptions for detached/fire-and-forget tasks, and adds tests intended to validate faulted and successful paths.
Changes:
- Added
Task.ObserveException()andTask<T>.ObserveException()to observet.Exceptionvia a continuation. - Added unit tests covering faulted and successful cases for both
TaskandTask<T>. - Added additional tests intended to ensure no unobserved-task-exception behavior occurs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| PowerKit/Extensions/TaskExtensions.cs | Adds ObserveException() overloads for Task and Task<T> via a continuation that reads t.Exception. |
| PowerKit.Tests/Extensions/TaskExtensionsTests.cs | Adds tests for faulted/successful cases and attempts to test unobserved-exception behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@copilot do we actually need separate implementations for |
No — separate implementations aren’t needed. |
|
@copilot please fix build errors |
Fixed in |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## prime #92 +/- ##
==========================================
+ Coverage 87.13% 87.18% +0.05%
==========================================
Files 75 76 +1
Lines 1352 1358 +6
Branches 236 236
==========================================
+ Hits 1178 1184 +6
Misses 122 122
Partials 52 52 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Detached (fire-and-forget) tasks that fault produce unobserved task exceptions, which can crash the process or generate noise via
TaskScheduler.UnobservedTaskException. This adds a lightweight way to explicitly suppress them when the exception cannot be meaningfully handled.Changes
TaskExtensions— addsObserveException()for bothTaskandTask<T>, registering anOnlyOnFaultedcontinuation that readst.Exceptionto mark it observedTaskExtensionsTests— covers faulted and successful cases for both task typesUsage