Skip to content
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

Bug: [return-await] should handle nested try-catch-finally blocks with "in-try-catch" option #8907

Closed
4 tasks done
kirkwaiblinger opened this issue Apr 12, 2024 · 0 comments · Fixed by #9031
Closed
4 tasks done
Assignees
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Milestone

Comments

@kirkwaiblinger
Copy link
Member

kirkwaiblinger commented Apr 12, 2024

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.2.2&showAST=es&fileType=.tsx&code=IYZwngdgxgBAZgV2gFwJYHsLwBQEoYDeAUDDMgE5iEmlmXW0wC%2B8qEwANh1cY6QPT8YwOHACmUZCBhjy5dORgALYBAAmHNgHMY6OLoTJZMKMGRQlNRuTHIE5LAAV5AW1QgxAOhsArCcjwAbitmGhZTcyVqMKImIiJQSFhEFAwsOAAmPAY6HjCTMwsc0go8xhY4Nk5uYtpBYVF-aVl5RRV1TQgdPQMjRUr2LjAQ0hs7BxhndDcPbzE-SSCQuNIKqqHamKYgA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6aRfWaJ2gQwDufSvnRgA2pETRoAe2iQANFGa180QrTJ98ZABaQAuuDABfEKaA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

async function f() {
  try {
    try {
    } finally {
      // affects error handling of outer catch
      return Promise.reject();
    }
  } catch {

  }
}

// or,
async function f2() {
  try {
  } catch {
    try {
    } finally {
      // affects error handling of outer finally
      return Promise.reject();
    }
  } finally {
    
  }
}

ESLint Config

module.exports = {
  "rules": {
    "@typescript-eslint/return-await": ["error", "in-try-catch"]
  }
}

tsconfig

{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Expected Result

I expect that the commented promises should flag as requiring await.

Actual Result

no errors

Additional Info

The in-try-catch deductions are generally buggy. Note that putting an await doesn't cause the rule to flag that it's unnecessary either, despite the rule's documentation implying that there will only be one correct choice in each scenario.

See also #8663

Note that putting a return in a catch suffers the same defect and is probably a more realistic example for this issue.

@kirkwaiblinger kirkwaiblinger added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Apr 12, 2024
kirkwaiblinger added a commit to kirkwaiblinger/typescript-eslint that referenced this issue Apr 12, 2024
kirkwaiblinger added a commit to kirkwaiblinger/typescript-eslint that referenced this issue Apr 12, 2024
@JoshuaKGoldberg JoshuaKGoldberg added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for maintainers to take a look labels Apr 29, 2024
@kirkwaiblinger kirkwaiblinger self-assigned this Apr 29, 2024
@kirkwaiblinger kirkwaiblinger modified the milestones: v8, 8.0.0 May 29, 2024
@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Jun 9, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
2 participants