Pattern: Non-descriptive error parameter name in catch
block
Issue: -
Using clear and consistent names for error parameters in catch
blocks improves code readability and debugging. Avoid using vague names like badName
or _
when the error is actually used in the catch block.
Example of incorrect code:
try {
} catch (badName) {}
try {
} catch (_) {
console.log(_);
}
promise.catch((badName) => {});
Example of correct code:
try {
} catch (error) {}
try {
} catch (_) {
console.log(123);
}
promise.catch((error) => {});