This rule raises an issue when error parameters in try/catch blocks, promise.catch() handlers, or
promise.then() rejection handlers don’t follow the configured naming convention (defaults to error).
Consistent naming of error parameters improves code readability and maintainability across your codebase. When developers use different names for
error parameters (err, e, exception, badName), it creates unnecessary cognitive overhead when
reading and maintaining code.
Consistent naming helps developers:
This rule applies to three common JavaScript error handling patterns:
try/catch blocks .catch() methods .then() rejection handlers (second parameter) The rule is flexible and allows descriptive names like fsError or authError when they provide meaningful context about
the type of error being handled.
While this is primarily a code style issue, inconsistent error parameter naming can slow down development and code reviews. It may also make debugging more difficult when developers need to quickly scan through error handling code.
Use the configured parameter name (defaults to error) for catch clause parameters.
try {
riskyOperation();
} catch (badName) { // Noncompliant
console.log(badName.message);
}
try {
riskyOperation();
} catch (error) {
console.log(error.message);
}