Sitelet https://github.com/fsprojects/FSharpLint/issues/686
Skip to content

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

Description

@knocte

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions