Skip to content

TypeScript · correctness

no-sentinel-return-on-catch

eslint:no-sentinel-return-on-catch

Disallow swallowing a caught error by returning an empty sentinel unless the error is handled or the sentinel is part of the function contract.

Default
error
Fix
none
Languages
typescript

Why

An unreported fallback makes operational failure indistinguishable from a legitimate empty result.

Fix

Rethrow, report the error before returning, or model expected absence with an explicit predicate, safe-parse, or result contract.

Before / after

Executed by this rule’s unit tests.

Before

Do not turn an unreported error into absence

src/load.ts · focus
function load() { try { return read(); } catch { return null; } }

After

Report an error before returning a fallback

src/load.ts · focus
function load() { try { return read(); } catch (error) { logger.warn('load failed', error); return null; } }

Limits

  • Recognized predicate, safe-parse, normal-path sentinel, deliberate parse, generated-client, and configured logging patterns are excluded.

Message IDs

noSentinelReturn

Options

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