typescript.async_without_error_handling
Stability
High
Detects async functions without proper error handling that can cause unhandled rejections.
Why It Matters
Section titled “Why It Matters”Unhandled async errors:
- Silent failures — Errors swallowed without logging
- Process crash — Unhandled rejections terminate Node.js
- Debugging nightmare — No stack trace, no context
Example
Section titled “Example”// ❌ Before (no error handling)async function fetchUser(id: string): Promise<User> { const response = await fetch(`/users/${id}`); return response.json();}
// Called without catchfetchUser("123").then(user => console.log(user));// ✅ After (with error handling)async function fetchUser(id: string): Promise<User> { try { const response = await fetch(`/users/${id}`); if (!response.ok) { throw new Error(`HTTP ${response.status}`); } return response.json(); } catch (error) { logger.error('Failed to fetch user', { id, error }); throw error; }}
// Or handle at call sitefetchUser("123") .then(user => console.log(user)) .catch(error => logger.error('Fetch failed', error));What Unfault Detects
Section titled “What Unfault Detects”- Async functions without try-catch
- Promise chains without .catch()
- Fire-and-forget async calls