redline
MediumError handlinglog-and-continue

Logs the error and carries on

Logs the error and carries on. Logs the error and carries on as if it worked. The caller gets no signal that this failed.

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

Why it matters

Logging an error and continuing means the caller thinks it worked. The log line is the only witness, and nobody reads it in time.

What to do

Rethrow after logging, or return a result the caller has to check.

Examples

Flagged
try {
  await charge(card);
} catch (e) {
  console.error(e);
}
Better
await charge(card); // the caller shows the decline

What it catches

It reads the shape of the code: functions, blocks, loops and calls. Languages: TypeScript and JavaScript, Python. 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 (e) {
  console.error(e);
}
src/app.py
try:
    go()
except ValueError as e:
    logger.warning(e)

Left alone

try {
  go();
} catch (e) {
  console.error(e);
  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": [
      "log-and-continue"
    ],
    "severity": {
      "log-and-continue": "low"
    }
  }
}

Read the source or report a false positive.