Skip to content

Coverlet flagging a branch for an async functions finally block where none exists #1337

Closed

Description

@bdurrani

I have the following class

namespace CovetletTest;

public record Data(int One, string Two);
public class DoerOfStuff
{
   private readonly ILogger<DoerOfStuff> _log;

   public DoerOfStuff(ILogger<DoerOfStuff> log)
   {
      _log = log;
   }
   
   public void StartWithoutWaiting(Data data)
   {
      Task.Run(() => ActualWork(data));
   }

   private async Task ActualWork(Data data)
   {
      var (one, two) = data;
      try
      {

         var res = one++;
         _log.LogInformation($"Res {res}");
      }
      catch(Exception exception)
      {
        _log.LogError(exception, "Something bad happened"); 
      }
      finally
      {
         _log.LogInformation("I'm finally here");
         string filePath = "simple.txt";
         string text = $"Hello World";

         await File.WriteAllTextAsync(filePath, text);
      } 
   }
}

When using coverlet, it is flagging the finally block for that class with a branch that doesn't exist

image

Not sure what is going on here. This is a .net 6 project.
I've attach a test project with the smallest reproduct I could find.

CovetletTest.zip

Activity

  1. MarcoRossignoli commented on May 24, 2022

    @MarcoRossignoli
    Collaborator

    Unfortunately that branches exist are emitted by Roslyn to handle the async/await state machine, in coverlet we try to elide looking for IL patterns. Look like we're failing here.

  2. Bertk commented on Sep 16, 2024

    @Bertk
    Collaborator

    Please verify whether the problem still exists using the latest coverlet 6.0.2 release.

  3. added
    SolvedThe issue is solved and can be closed
    and removed
    SolvedThe issue is solved and can be closed
    on May 9, 2026
  4. added
    SolvedThe issue is solved and can be closed
    on May 12, 2026
  5. Bertk commented on May 14, 2026

    @Bertk
    Collaborator

    This issue is fixed with PR #1904.

    Image
  6. 41 remaining items

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

    SolvedThe issue is solved and can be closedbugSomething isn't workingcoverlet-coretenet-coverageIssue related to possible incorrect coveragewith reproIssue with repro

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions