redline
LowError handlingerror-discarded

Error caught and ignored

Error caught and ignored. Catches an error and never looks at it. Every failure, expected or not, takes this path.

This is how the comment reads inline, under the flagged line.

Why it matters

A catch that never reads the error handles every failure the same way, including the ones you didn't expect.

What to do

Check the error type and rethrow anything you didn't mean to handle.

Examples

Flagged
try {
  parse(s);
} catch {
  useDefault();
}
Better
try {
  parse(s);
} catch (e) {
  if (!(e instanceof SyntaxError)) throw e;
  useDefault();
}

What it catches

It reads the shape of the code: functions, blocks, loops and calls. Languages: TypeScript and JavaScript. Scope: All files. These cases are the rule's own tests: the first set must be flagged and the second must not.

Flagged

try {
  go();
} catch {
  fallback();
}

Left alone

try {
  go();
} catch (e) {
  if (e instanceof X) fallback(e);
  else throw e;
}

Research

Empty catch, `except: pass`, `.catch(() => {})`, and catch blocks that only log. The failure disappears from the person who could fix it.

Turn it off or change it

In a config file for the CLI, or in the API's rules field:

{
  "rules": {
    "disable": [
      "error-discarded"
    ],
    "severity": {
      "error-discarded": "medium"
    }
  }
}

Read the source or report a false positive.