Skip to main content

What it flags

A JS/TS catch block in non-test code is empty, or only calls console.*, logger.* or this.logger.* while the code after the try carries on as if it had succeeded. A comment inside the block, a comment directly above the try that explains the error handling (for example // Optional cache write; ignore failures or // Fall back to built-in settings.), an optional require() or import() probe, a cleanup in a finally or catch block, and a try made only of close, destroy, release-style calls are accepted. A catch that rethrows, returns or records a failure is not reported. A comment above the try that does not mention errors or a fallback, such as a section heading like // Save invoice, does not excuse the catch. A .catch() callback on a promise is checked the same way. The rule reports an arrow function or function expression with a block body that is empty or only logs, when the receiver is a promise: new Promise(...), a Promise.*() call, a fetch() call, a .then(), .catch() or .finally() chain, or a variable or parameter declared as Promise or PromiseLike. A comment inside the callback excuses it. A callback that returns a fallback value, rethrows or records the error is not reported. A callback whose logged message explains the fallback, such as console.warn("falling back to defaults"), is also not reported. A catch method on an object that is clearly not a promise is not reported, but a .then() chain is recognized by name, so a non-promise object that exposes then() can still match. An empty catch at the end of a function is accepted when the try ends with a value return and there is no finally block. The declared return type must be a union with an explicit undefined member, such as string | undefined, or an async function’s Promise of such a union, such as Promise<string | undefined>. The rule is meant for authored source, so it skips copied bundles: static assets, vendored and compiled directories, and JavaScript files with a bundle banner. A bundle banner is a leading /*! For license information please see <name>.LICENSE.txt */ comment, or a /*! or @license comment that starts with a name and version number. A plain license comment, or one that only mentions license information, is not enough to skip a file.

Example from the editor

Flagged example

Possible rewrite

Handle, rethrow or report the error so the code after the try does not run as if it succeeded.

Configuration

Set the rule to "off" in loadwise.config.json to drop its findings: