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.

no-useless-return has a false negative with try/catch

See original GitHub issue

Tell us about your environment

  • ESLint Version: 3.9.0
  • Node Version: 6.9.1
  • npm Version: 3.10.8

What parser (default, Babel-ESLint, etc.) are you using?

default

Please show your full configuration:

rules:
  no-useless-return: error

What did you do? Please include the actual source code causing the issue.


function foo() {
  try {
    return;
  } catch (err) {
    foo();
  }
}

What did you expect to happen?

This should report an error, because the return statement can be safely removed.

What actually happened? Please include the actual, raw output from ESLint.

No error.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:12 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
mysticateacommented, Oct 30, 2016

Thank you for this issue.

In fact, this is caused by the current code path analyzer. Since the analyzer cannot know the places which throw exceptions, it generates 2 code paths which go to the catch block from both the first statement and the last statement in the try block (edit: and from throw statements). But in this case, the return; statement throws no exception clearly. I will investigate to improve the code path.

1reaction
ljharbcommented, Dec 26, 2022

This has an open PR, #16693

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error handling, "try...catch" - The Modern JavaScript Tutorial
The try...catch construct has two main blocks: try , and then catch : ... code below returns an error for negative or non-integer...
Read more >
How to write trycatch in R - exception - Stack Overflow
As we've specified that NA should be returned in case of error, the third element in y is NA . If we'd have...
Read more >
Error handling in R with tryCatchLog: Catching, logging, post ...
Use tryCatch to handle errors. With tryCatch you can handle errors as you want: an.error.occured <- FALSE ...
Read more >
no-useless-return - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
disable no-useless-catch
unnecessary try/catch wrapper no-useless-catch. A catch clause that only rethrows the original error is redundant, and has no effect on the runtime behavior ......
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