Skip to content

Commit

Permalink
Merge pull request #63 from weyert/patch-1
Browse files Browse the repository at this point in the history
fix: potential error in isTryCatchStatement
gkouziik authored Jan 3, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 0520676 + 922ded3 commit 081d149
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/rules/detect-unhandled-async-errors.js
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@ function isIfWithReturn (bodyArg) {
function isTryCatchStatement (bodyArg) {
return bodyArg.type === 'TryStatement' &&
bodyArg.handler.type === 'CatchClause' &&
bodyArg.handler.param &&
/^(e|err|error|Error|anySpecificError)$/.test(bodyArg.handler.param.name)
}

14 changes: 12 additions & 2 deletions tests/lib/rules/detect-unhandled-async-errors.js
Original file line number Diff line number Diff line change
@@ -19,8 +19,9 @@ const invalidIfWithThrow = "async function run() {const success = await alert('d
const invalidIfWithThrowTwo = "async function run() {const success = await alert('do something'); if(err) throw new handle('error')}"
const validCatch = "async function run(out) { await out.catch(error => alert('there is an error'))}"
const invalidCatch = "async function run(out) { await out }"
const validCatchError = "async function clientErrorHandler(err, req, res, nextMiddleware) { alert('there is an error') }"

var ruleTester = new RuleTester({
var ruleTester = new RuleTester({
parserOptions: { ecmaVersion: 2018 }
})

@@ -76,4 +77,13 @@ ruleTester.run('detect-unhandled-async-errors', rule, {
}]
}
]
})
})

ruleTester.run('detect-unhandled-async-errors', rule, {
valid: [
{ code: validCatchError }
],

invalid: [
]
})

0 comments on commit 081d149

Please sign in to comment.