question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Task to AsyncResult transition wraps `Exception` into the `AggregateException`

See original GitHub issue

Describe 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:

  1. Call Task returning method via return! in an asyncResult CE
  2. Catch exception
  3. 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:open
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
TheAngryByrdcommented, Nov 23, 2021

Hey @NinoFloris see any downsides to doing this?

1reaction
xperiandricommented, Nov 17, 2021

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found