Shallow Catch

Catch blocks that are empty, ignore the error, or log without it

warningReliabilityshallow-catch

Severity depends on context. Warning when the error is ignored: the block is empty, or doesn't log, rethrow or return it. Info when it only logs with console.log, or logs without the error itself. A block that logs the error with console.error, rethrows it or returns an error response isn't reported.

Why this matters

An empty catch block hides failures completely. The operation fails, but your code continues as if it succeeded — causing data corruption, silent data loss, or inconsistent state.

Example

Flaggedlib/billing.ts
try {
  await db.user.update({
    where: { id },
    data: { plan: "pro" },
  });
} catch (e) {
  // TODO: handle error
}
Fixedlib/billing.ts
try {
  await db.user.update({
    where: { id },
    data: { plan: "pro" },
  });
} catch (error) {
  console.error("Failed to update user plan:", error);
  throw error;
}

How to fix

Log the error, re-throw it, or handle it explicitly in every catch block. Never leave catch blocks empty.

Reference

In the output
Findings carry "ruleId": "shallow-catch" in --json and the same id in SARIF and in the terminal.
Silence one line
// prodlint-disable-next-line shallow-catch
Silence a whole file
// prodlint-disable shallow-catch at the top of the file
How it works
Reads the syntax tree, with a text fallback for files that don't parse. Source on GitHub