usePromiseRejectErrors (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Diagnostic Category:
lint/nursery/usePromiseRejectErrors - This rule doesn’t have a fix.
- The default severity of this rule is warning.
- Sources:
- Same as
prefer-promise-reject-errors
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "usePromiseRejectErrors": "error" } } }}Description
Section titled “Description”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.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”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());Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.