fsprojects / FSharpLint

Lint tool for F#
https://fsprojects.github.io/FSharpLint/
MIT License
300 stars 73 forks source link

Warn about possibly unreachable try-catch with Async jobs #686

Open knocte opened 5 months ago

knocte commented 5 months ago

Sometimes when we want to add a try-catch to a certain asynchronous function, we go from:

let Foo(): Async<'Bar> =
    DoSomething()

to:

let Foo(): Async<'Bar> =
    try
        DoSomething()
    with
    | ex -> DoSomethingElse()

However, most of the time, the above change is wrong, because the exception only happens when the async job is running, not when the async job is being composed (as it's happening in the above). If we had added the try-with block inside an async{} block, this would have been fine.

Maybe we could create a rule that warns against this, and recommends converting 'Bar to Result<'Bar,'Err> instead.