# prefer-promise-reject-errors

> Require an `Error` object as the reason of a promise rejection

A promise rejected with a string or a plain object has no stack trace, so you can't see where it failed. The code that catches it and reads `error.message` gets `undefined`.

The rule checks `Promise.reject()` and the `reject` function of `new Promise((resolve, reject) => ...)`. It reports a reason that can't be an `Error`: a literal, an object literal, `undefined`, or nothing. A variable or a call's result isn't reported, because the rule can't tell what it holds.

{/* 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]
"prefer-promise-reject-errors" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"prefer-promise-reject-errors" = ["error", {
  allowEmptyReject = false,
}]
```

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

## Examples

Reported:

{/* bad {"count": 2} */}
```js
Promise.reject("User not found");

new Promise((resolve, reject) => {
  reject({ code: 404 });
});
```

Not reported:

{/* good */}
```js
Promise.reject(new Error("User not found"));

new Promise((resolve, reject) => {
  reject(new RangeError("Page out of range"));
});

Promise.reject(reason);
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `allowEmptyReject` | `false` | Allow a rejection with no argument. |

{/* good {"options": [{"allowEmptyReject": true}]} */}
```js
Promise.reject();
```

Writing out `undefined` is still reported:

{/* bad {"options": [{"allowEmptyReject": true}]} */}
```js
Promise.reject(undefined);
```
