handle-callback-err
Require callbacks to use their error parameter
deprecated
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#
example.js1 problem
fs.readFile(path, "utf8", function (err, text) {Expected error to be handled.
render(text);
});example.jsNo problems
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.
example.jswith
"error"1 problemfs.readFile(path, "utf8", (error, text) => {Expected error to be handled.
render(text);
});example.jswith
"^(err|error)$"2 problemsfs.readFile(path, "utf8", (error, text) => {Expected error to be handled.
render(text);
});
fs.unlink(path, (err) => {Expected error to be handled.
done();
});With the default, a parameter named error isn't checked:
example.jsNo problems
fs.readFile(path, "utf8", (error, text) => {
render(text);
});