typescript.empty_catch
Correctness
High
Common in Incidents
Detects empty catch blocks that silently swallow errors.
Why It Matters
Section titled “Why It Matters”Empty catch blocks hide real problems:
- Silent failures — Operations fail with no indication
- Debugging nightmare — Errors vanish without trace
- Masked bugs — Logic errors become invisible
- Data corruption — Failures occur but code continues
Every swallowed error is a bug waiting to surprise you.
Example
Section titled “Example”// ❌ Beforetry { riskyOperation();} catch (e) {}If riskyOperation fails, you’ll never know.
// ✅ Aftertry { riskyOperation();} catch (error) { console.error('Unhandled error:', error); // Or re-throw, or handle specifically}What Unfault Detects
Section titled “What Unfault Detects”- Empty catch blocks
catch (e) {} - Catch with only comments
- Catch that ignores the error parameter
Auto-Fix
Section titled “Auto-Fix”Unfault can add error logging to empty catch blocks when there’s no explicit suppression comment.
Handling Patterns
Section titled “Handling Patterns”// Log and continue (non-critical)try { sendAnalytics(event);} catch (error) { console.error('Analytics failed:', error); // Non-critical, continue execution}
// Log and re-throw (preserve stack)try { critical();} catch (error) { logger.error('Critical operation failed', { error }); throw error;}
// Handle specific errorstry { await fetchData();} catch (error) { if (error instanceof NetworkError) { return cachedData; } throw error;}
// Explicit ignore (document why)try { optionalCleanup();} catch { // Intentionally ignored: cleanup is best-effort}