Skip to content

usePromiseRejectErrors (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"usePromiseRejectErrors": "error"
}
}
}
}

Require Error objects as Promise rejection reasons.

Error objects capture a stack trace that helps locate the cause of a rejection. Rejecting with a string or another non-Error value loses this information.

This rule checks Promise.reject() and calls to the second parameter of a new Promise() executor. Values that could be errors, such as function calls and unknown variables, are allowed without inspecting their types.

Promise.reject("Request failed");
code-block.js:1:1 lint/nursery/usePromiseRejectErrors ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This Promise rejection reason is not an Error object.

> 1 │ Promise.reject("Request failed");
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

Error objects capture a stack trace that helps locate the cause of a rejection.

Pass an Error object to preserve debugging information.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

new Promise((resolve, reject) => reject(42));
code-block.js:1:34 lint/nursery/usePromiseRejectErrors ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This Promise rejection reason is not an Error object.

> 1 │ new Promise((resolve, reject) => reject(42));
^^^^^^^^^^
2 │

Error objects capture a stack trace that helps locate the cause of a rejection.

Pass an Error object to preserve debugging information.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Promise.reject();
code-block.js:1:1 lint/nursery/usePromiseRejectErrors ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This Promise rejection reason is not an Error object.

> 1 │ Promise.reject();
^^^^^^^^^^^^^^^^
2 │

Error objects capture a stack trace that helps locate the cause of a rejection.

Pass an Error object to preserve debugging information.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Promise.reject(new Error("Request failed"));
new Promise((resolve, reject) => reject(new TypeError("Invalid value")));
Promise.reject(getError());