Skip to content

[return-await] await should be required in catch block only when it has a finally block #2344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
danthegoodman opened this issue Jul 30, 2020 · 3 comments · Fixed by #2356
Closed
Labels
bug Something isn't working good first issue Good for newcomers package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@danthegoodman
Copy link

Repro

async function main(){
  try {
    throw "foo"
  } catch(e) {
    return Promise.resolve("bar");
  }
}
{
  "rules": {
    "no-return-await": ["error"],
    "@typescript-eslint/return-await": ["error", "in-try-catch"]
  }
}

Expected Result

No error

Actual Result

Returning an awaited promise is required in this context. (line 5)

Additional Info

This issue can cause this rule to be in conflict with eslint's no-return-await. Adding the await to resolve @typescript-eslint/return-await will then trigger no-return-await

function hasErrorHandler(node): Determines whether a thrown error from this node will be caught/handled within this function rather than immediately halting this function. For example, a statement in a try block will always have an error handler. A statement in a catch block will only have an error handler if there is also a finally block.
https://github.com/eslint/eslint/blob/master/lib/rules/no-return-await.js#L51-L58

Versions

package version
@typescript-eslint/eslint-plugin 3.7.1
@typescript-eslint/parser 3.7.1
TypeScript 3.9.7
ESLint 7.5.0
node 12.16.1
yarn 1.22.4
@danthegoodman danthegoodman added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Jul 30, 2020
@bradzacher bradzacher added bug Something isn't working good first issue Good for newcomers and removed triage Waiting for team members to take a look labels Jul 30, 2020
@bradzacher
Copy link
Member

This issue can cause this rule to be in conflict with eslint's no-return-await.

You shouldn't be using the two rules in tandem. This rule is intended to be a better version of the base rule.
https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/return-await.md#how-to-use

@danthegoodman
Copy link
Author

@bradzacher Ah, good to know! Thank you for pointing that out.

@soobing
Copy link
Contributor

soobing commented Aug 3, 2020

I will try this Issue 😊

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working good first issue Good for newcomers package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
3 participants