Task to AsyncResult transition wraps `Exception` into the `AggregateException`
See original GitHub issueDescribe the bug
member this.AsyncAcquireTokenInteractively (uiThread, correlationId) = asyncResult {
do! Async.SwitchToContext uiThread
let builder =
pca.AcquireTokenInteractive(options.Scopes)
.WithCorrelationId(correlationId)
if not (isNull configureInteractive) then configureInteractive.Invoke(builder)
try return! builder.ExecuteAsync() // FSharp.Control.FusionTasks is used not to write |> Async.AwaitTask
with :? MsalClientException as ex -> return! Error ex.ErrorCode
}
Matching by the MsalClientException does not happen as it is wrapped by the AggregateException.
To Reproduce Steps to reproduce the behavior:
- Call Task returning method via
return!in anasyncResultCE - Catch exception
- You will see that it is always the
AggregateException.
Expected behavior A clear and concise description of what you expected to happen.
Desktop (please complete the following information):
- Version 2.10.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8 (1 by maintainers)
Top Results From Across the Web
c# - Wait for async Task without wrapping exceptions in ...
I am going to use these in a command line application. So I need to call them synchronously a lot. No, you don't....
Read more >Async.Await overload (esp. AwaitTask without throwing ...
I propose including AwaitTaskCorrect (maybe with another name) open System open System.Threading.Tasks type Async with static member ...
Read more >Exception handling (Task Parallel Library)
To propagate all the exceptions back to the calling thread, the Task infrastructure wraps them in an AggregateException instance.
Read more >Tasks and the AggregateException
In this scenario when an exception occurs in a task, it will wrap the exception(s) within an AggregateException.
Read more >Exception Handling In Asynchronous Code - Hamid Mosalla
To do that they're wrapped inside AggregateException and returned to the caller. So when we await a task, we only get the first...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hey @NinoFloris see any downsides to doing this?
As long as it is a FSharp.Core issue I propose to use a corrected way of awaiting tasks https://github.com/jet/FsKafka/blob/6c6186f822a221adf0ad06e8a44a392aa55aa8ec/src/FsKafka/Infrastructure.fs#L14 instead of
Async.AwaitTask