# 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:

{/* bad */}
```js
fs.readFile(path, "utf8", function (err, text) {
  render(text);
});
```

Not reported:

{/* good */}
```js
fs.readFile(path, "utf8", function (err, text) {
  if (err) {
    showError(err);
    return;
  }
  render(text);
});
```

## Options

```toml 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.

{/* bad {"options": ["error"]} */}
```js
fs.readFile(path, "utf8", (error, text) => {
  render(text);
});
```

{/* bad {"options": ["^(err|error)$"], "count": 2} */}
```js
fs.readFile(path, "utf8", (error, text) => {
  render(text);
});

fs.unlink(path, (err) => {
  done();
});
```

With the default, a parameter named `error` isn't checked:

{/* good */}
```js
fs.readFile(path, "utf8", (error, text) => {
  render(text);
});
```
