Linter · Rules
handle-callback-err
Require callbacks to use their error parameter
A Node.js-style callback gets the error as its first argument. If the function never looks at it, a failure goes unnoticed and the code carries on with an undefined result.
The rule reports a function if its first parameter is named err and is never used. Any use counts as handling it.
ESLint has deprecated this rule. Use n/handle-callback-err instead.
Examples
Reported:
fs.readFile(path, "utf8", function (err, text) {
render(text);
});
Not reported:
fs.readFile(path, "utf8", function (err, text) {
if (err) {
showError(err);
return;
}
render(text);
});
Options
bunfig.toml
[lint.rules]
handle-callback-err = ["error", "^(err|error)$"]
The only option is a string with the name of the error parameter. The default is "err". A string that starts with ^ is a regular expression that the name must match.
fs.readFile(path, "utf8", (error, text) => {
render(text);
});
fs.readFile(path, "utf8", (error, text) => {
render(text);
});
fs.unlink(path, (err) => {
done();
});
With the default, a parameter named error isn't checked:
fs.readFile(path, "utf8", (error, text) => {
render(text);
});