Skip to content

Fix TypeError when checking a try/finally block with no catch#83

Open
nkeynes wants to merge 1 commit intogkouziik:masterfrom
nkeynes:master
Open

Fix TypeError when checking a try/finally block with no catch#83
nkeynes wants to merge 1 commit intogkouziik:masterfrom
nkeynes:master

Conversation

@nkeynes
Copy link
Copy Markdown

@nkeynes nkeynes commented Sep 16, 2024

Currently the detect-unhandled-async-errors rule raises a TypeError when scanning a try block with no catch, e.g.

async function fn() {
   try {
      await foo();
   } finally {
      console.log("done");
   }
}

results in an error:

TypeError: Cannot read properties of null (reading 'type')
Occurred while linting <source-filename>:<line>
Rule: "security-node/detect-unhandled-async-errors"
    at isTryCatchStatement (/Users/nkeynes/src/dylan/node_modules/.pnpm/eslint-plugin-security-node@1.1.4/node_modules/eslint-plugin-security-node/lib/rules/detect-unhandled-async-errors.js:41:21)
    at FunctionDeclaration (/Users/nkeynes/src/dylan/node_modules/.pnpm/eslint-plugin-security-node@1.1.4/node_modules/eslint-plugin-security-node/lib/rules/detect-unhandled-async-errors.js:113:19)
    at ruleErrorHandler (/Users/nkeynes/src/dylan/node_modules/.pnpm/eslint@8.50.0/node_modules/eslint/lib/linter/linter.js:1091:28)
    at /Users/nkeynes/src/dylan/node_modules/.pnpm/eslint@8.50.0/node_modules/eslint/lib/linter/safe-emitter.js:45:58

This PR just adds a check that the handler body exists (and corresponding test).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant