Skip to content

Latest commit

 

History

History
67 lines (50 loc) · 1.15 KB

File metadata and controls

67 lines (50 loc) · 1.15 KB

no-empty-catch

Disallow empty catch blocks that silently swallow errors.

Rule Details

Property Value
Type problem
Fixable No
Recommended warn
Strict error

Rationale

An empty catch block discards the error entirely. The caller has no indication that anything went wrong, diagnostics are impossible, and bugs become untraceable. Every caught error must be handled in some meaningful way: logged, re-thrown, returned as a result, or surfaced to the user.

Examples

✅ Correct

try {
  riskyOperation();
} catch (err) {
  logger.error('riskyOperation failed', err);
}

try {
  connectToDb();
} catch (err) {
  throw new Error(`Database connection failed: ${err}`);
}

try {
  cleanup();
} catch {
  throw new Error('Cleanup step failed');
}

❌ Incorrect

try {
  riskyOperation();
} catch (err) {}

try {
  connectToDb();
} catch {}

try {
  cleanup();
} catch (err) {
} finally {
  teardown();
}

Configuration

This rule has no options:

'zero-tolerance/no-empty-catch': 'error'