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] awaited promise allowed in terminal catch block #8663

Closed
4 tasks done
kirkwaiblinger opened this issue Mar 13, 2024 · 0 comments · Fixed by #9031
Closed
4 tasks done

Bug: [return-await] awaited promise allowed in terminal catch block #8663

kirkwaiblinger opened this issue Mar 13, 2024 · 0 comments · Fixed by #9031
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

Comments

@kirkwaiblinger
Copy link
Member

kirkwaiblinger commented Mar 13, 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.4.2&fileType=.tsx&code=IYZwngdgxgBAZgV2gFwJYHsLwBQEoYDeAUDDMgE5iEkwC%2BMUwyUAFtaaeQKbILlbAA7sFTIYABXLoAtqhBcAdNwBWXKMjwBuGrSK0gA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6aRfWaJ2gQwDufSvnRgA2pETRoAe2iQANFGa180QrTJ98ZABaQAuuDABfEKaA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

async function f() {
  try {
  } catch {
    return await Promise.reject();
  }
}

ESLint Config

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

tsconfig

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

Expected Result

Expected rule to flag on awaited promise in terminal catch block. From the docs:

  • if you return a promise within a catch, and there is no finally, then it must not be awaited.

see https://typescript-eslint.io/rules/return-await/#in-try-catch

Actual Result

no error reported

Additional Info

Strangely, there is actually a valid test case right now that is asserting this incorrect behavior

{
code: `
async function test() {
const res = await Promise.resolve('{}');
try {
async function nested() {
return Promise.resolve('ok');
}
return await nested();
} catch (error) {
return await Promise.resolve('error');
}
}
`,
},
],

@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 Mar 13, 2024
kirkwaiblinger added a commit to kirkwaiblinger/typescript-eslint that referenced this issue Mar 13, 2024
kirkwaiblinger added a commit to kirkwaiblinger/typescript-eslint that referenced this issue Mar 13, 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
@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