Guides Claude in reviewing and writing robust error-handling code. Covers distinguishing recoverable from unrecoverable errors, implementing retry-with-backoff patterns, structured error logging with correlation IDs, and crafting helpful user-facing error messages. Use when the user asks about error handling, exception management, try-catch patterns, error logging, retry logic, or debugging runtime failures in any codebase.
68
81%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
Use this skill when reviewing or writing code that needs to handle unexpected failures.
When you encounter an error, ask in order:
Catching an error and silently continuing is almost always wrong. At minimum, log the error with enough context to understand what happened.
Bad:
try {
await saveRecord(record);
} catch (err) {
// ignore
}Good:
try {
await saveRecord(record);
} catch (err) {
logger.error({ err, recordId: record.id, requestId: ctx.requestId }, 'Failed to save record');
throw err; // re-throw unless you have a deliberate fallback
}Validate inputs at system boundaries and reject bad ones loudly. Inside trusted internal code, prefer assumptions over re-validation.
Retry-with-backoff pattern:
async function withRetry(fn, { maxAttempts = 3, baseDelayMs = 200 } = {}) {
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
try {
return await fn();
} catch (err) {
if (!isTransient(err) || attempt === maxAttempts) throw err;
await sleep(baseDelayMs * 2 ** (attempt - 1));
}
}
}When you log an error, include:
Bad:
console.error('something went wrong');Good:
logger.error(
{ err, requestId: ctx.requestId, userId: ctx.userId },
'Payment charge failed'
);If the error reaches a user, show a helpful message. Tell them what happened and what they can do about it. Never expose internal stack traces or system details.
Example user-facing error response:
{
"error": "payment_failed",
"message": "We couldn't process your payment. Please check your card details and try again, or contact support if the problem persists.",
"requestId": "req_abc123"
}73eda88
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.