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.

bug: finally block in async function indicates incorrect missing block coverage

See original GitHub issue

Observed Behavior

The following code:

async function abc() {
  try {
    return 'abc';
  } finally {
    console.log('in finally');
  } // this is a covered line but uncovered branch
}

abc()

Ends up having the following coverage output:

{
          "functionName": "abc",
          "ranges": [
            {
              "startOffset": 0,
              "endOffset": 146,
              "count": 1
            },
            {
              "startOffset": 97,
              "endOffset": 145,
              "count": 0
            }
          ],
          "isBlockCoverage": true
        }
}

This indicates that the following characters were tracked as an uncovered block:

// this is a covered line but uncovered branch\n

Expected behavior

Coverage should be 100% in the above example.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
evocateurcommented, Feb 6, 2021

@bcoe Perfectly fair! Especially considering it’s going into maintenance mode in like, 2 months? So I’ll probably drop v12 before I even finish this wee babby of a tool, lol.

0reactions
bcoecommented, Nov 3, 2022

@xolott would you be able to provide a minimal breaking example, this would help in investigating the underlying cause.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Finally in Promises & Try/Catch
If your finally block does not include a return statement, it has no effect on the return value. However, if you return a...
Read more >
javascript - await in finally block of async function causes ...
When a Promise rejects, it must be handled before the current call stack clears, or there will be an unhandled rejection. You have:...
Read more >
Practical Guide to Fp-ts P3: Task, Either, TaskEither
Some of the functions might never fail but are asynchronous out of ... are forced to handle these errors using a try-catch-finally block....
Read more >
Error Messages
Test File Errors No tests found This message means that Cypress was unable to find ... Support file missing or invalid; Error Loading...
Read more >
Code Inspections in JavaScript and TypeScript
Starting from ECMAScript 6, JavaScript blocks introduce new ... Missing await for an async function call ... Code is not covered by Flow....
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