Skip to content

typescript.async_without_error_handling

Stability High

Detects async functions without proper error handling that can cause unhandled rejections.

Unhandled async errors:

  • Silent failures — Errors swallowed without logging
  • Process crash — Unhandled rejections terminate Node.js
  • Debugging nightmare — No stack trace, no context
// ❌ Before (no error handling)
async function fetchUser(id: string): Promise<User> {
const response = await fetch(`/users/${id}`);
return response.json();
}
// Called without catch
fetchUser("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 site
fetchUser("123")
.then(user => console.log(user))
.catch(error => logger.error('Fetch failed', error));
  • Async functions without try-catch
  • Promise chains without .catch()
  • Fire-and-forget async calls