# n/handle-callback-err

> Require callbacks to use their error parameter

A Node.js 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 a result that's `undefined`.

The rule reports a function with a first parameter named `err` that's never used in its body. Any use counts. The rule doesn't check what you do with the error.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"n/handle-callback-err" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
fs.readFile("config.json", (err, data) => {
  start(JSON.parse(data));
});
```

Not reported:

{/* good */}
```js
fs.readFile("config.json", (err, data) => {
  if (err) {
    throw err;
  }
  start(JSON.parse(data));
});
```

## Options

The option is the name of the error parameter. The default is `"err"`. If it starts with `^`, it's treated as a regular expression.

```toml bunfig.toml
[lint.rules]
"n/handle-callback-err" = ["error", "^(err|error)$"]
```

{/* bad {"options": ["^(err|error)$"], "count": 2} */}
```js
server.close(function (error) {
  console.log("closed");
});

socket.end(function (err) {
  console.log("ended");
});
```

A plain name replaces `err`, so `err` is no longer checked:

{/* good {"options": ["error"]} */}
```js
socket.end(function (err) {
  console.log("ended");
});
```
