Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/rules/detect-unhandled-async-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
14 changes: 12 additions & 2 deletions tests/lib/rules/detect-unhandled-async-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
})

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

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

invalid: [
]
})