BetaViberTest is in active development — expect breaking changes.
Overview
#009mediumCode Quality
Missing Error Handling
Detects async operations and API calls without proper error handling.
Rule ID:
missing-error-handlingExamples#
BadNo try/catch, empty catch, console-only catch
// No error handling at all
async function fetchUser(id: string) {
const res = await fetch(`/api/users/${id}`);
const data = await res.json();
return data;
}
// Empty catch — silently swallows errors
try {
await saveOrder(order);
} catch (e) {}
// Console-only — no real handling
try {
await processPayment(amount);
} catch (error) {
console.log(error);
}GoodProper error handling at every level
async function fetchUser(id: string): Promise<User> {
try {
const res = await fetch(`/api/users/${id}`);
if (!res.ok) {
throw new Error(`Failed to fetch user: ${res.status}`);
}
return await res.json();
} catch (error) {
logger.error('fetchUser failed', { id, error });
throw error; // Re-throw for caller to handle
}
}
// Meaningful error handling
try {
await processPayment(amount);
} catch (error) {
reportToSentry(error);
notifyUser('Payment failed. Please try again.');
throw error;
}What It Detects#
mediumAsync function without try/catch
Async function "{funcName}" has no try/catch block
Fix: Wrap the async body in try/catch.
mediumfetch()/axios call without error handling
{callName}() call without error handling
Fix: HTTP calls can fail. Wrap in try/catch or add .catch().
highEmpty catch block
Empty catch block silently swallows errors
Fix: Handle the error: log it, report to monitoring, or re-throw.
mediumConsole-only catch block
Catch block only logs error without proper handling
Fix: Consider reporting to an error monitoring service.
mediumReact project without ErrorBoundary
React project has no ErrorBoundary component
Fix: Add an ErrorBoundary: npm install react-error-boundary.
Configuration#
This rule is enabled by default. To disable it:
.vibertestrc.jsonjson
{
"rules": {
"missing-error-handling": {
"enabled": false
}
}
}