Skip to content

TypeScript · correctness

no-log-only-catch

eslint:no-log-only-catch

Disallow `catch` clauses that only log (or silently do nothing) and then swallow the error; rethrow or handle it instead.

Default
error
Fix
none
Languages
typescript

Why

Swallowing an exception after logging lets execution continue as if the operation succeeded.

Fix

Rethrow the error, return an explicit fallback, or perform concrete recovery.

Before / after

Executed by this rule’s unit tests.

Before

Do not only log a failure

src/task.ts · focus
try { run(); } catch (error) { console.error(error); }

After

Preserve failure after logging

src/task.ts · focus
try { run(); } catch (error) { console.error(error); throw error; }

Limits

  • Documented intentional ignores, tests, and catches with observable recovery are excluded.

Message IDs

emptyCatchnoLogOnlyCatch

Options

{
  "additionalProperties": false,
  "properties": {
    "logFunctions": {
      "items": {
        "type": "string"
      },
      "type": "array"
    },
    "loggerNames": {
      "items": {
        "type": "string"
      },
      "type": "array"
    }
  },
  "type": "object"
}