fsprojects / fsprojects/FSharpLint

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

Open
#686 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
F#
Stars
327
Forks
74
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No file, test, or entry point is named. Start by locating how FSharpLint defines and tests rules for F# async expressions, then determine how to distinguish try-with around async composition from handling inside async{}. Done means a warning and recommendation appear only for the unreachable pattern, with coverage for the valid form.

Written by the indexing model from the issue text.

Assessment

Tech stack
fsharp
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.