Skip to content

typescript.promise_no_catch

Stability High Causes Production Outages

Detects Promises without .catch() handler or try/catch in async functions.

Unhandled promise rejections can crash Node.js:

  • Process crash — Node.js 15+ crashes on unhandled rejections
  • Silent failures — Earlier versions just warn and continue
  • Lost errors — Rejections vanish into the void
  • Unpredictable state — Operations fail but code assumes success

Every promise must have error handling.

// ❌ Before
fetchData().then(data => process(data));
// If fetchData rejects, nothing catches it
async function loadUser() {
const user = await getUser(id); // No try/catch
return user;
}
// ✅ After
fetchData()
.then(data => process(data))
.catch(error => console.error('Failed to fetch:', error));
async function loadUser() {
try {
const user = await getUser(id);
return user;
} catch (error) {
console.error('Failed to load user:', error);
throw error;
}
}
  • .then() without .catch()
  • await without surrounding try/catch
  • Floating promises (not awaited or returned)

Unfault can add .catch() handlers or wrap in try/catch when the promise chain is clearly identified.

// Always chain .catch() with .then()
promise
.then(handleSuccess)
.catch(handleError);
// Use try/catch with async/await
async function doWork() {
try {
await step1();
await step2();
} catch (error) {
handleError(error);
}
}
// For fire-and-forget, handle explicitly
void sendAnalytics(event).catch(console.error);
// Top-level async
main().catch(error => {
console.error('Unhandled error:', error);
process.exit(1);
});
// Node.js 15+ crashes on unhandled rejections
// You can customize this:
process.on('unhandledRejection', (reason, promise) => {
console.error('Unhandled Rejection:', reason);
// Decide: log and continue or exit
});