error-handling-architecture
Skill6 starsChanged 6 months agoMITView on GitHub
When designing how a system recovers from and reports failures.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- MohOneX/claude-opus-skillstheir own version, first seen Jun 6, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- MohOneX/claude-opus-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository13 other files it gives its agents.
- caching-strategiesSkill
- event-driven-designSkill
- logging-observability-standardsSkill
- api-design-restSkill
- database-query-optimizationSkill
- code-review-guidelinesSkill
- ci-cd-pipeline-architectureSkill
- debugging-strategiesSkill
- git-workflow-branchingSkill
- dom-security-hardeningSkill
- react-component-designSkill
- state-management-patternsSkill
- accessibility-ui-designSkill
The file
We split this skill into the rules it gives an agent
11 rules. About 0 are common, 9 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈9
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 49
Define Error Classes: Create base AppError class with statusCode, isOperational flag, and metadata
- Distinctive: line 51
Centralize Middleware: Add framework-level error handler to catch ALL exceptions globally
- Distinctive: line 55
Test Error Paths: Verify error handling works for all failure scenarios
- Very specific: line 58
MUST NEVER silently swallow exceptions (catch(e) {})
- Distinctive: line 59
MUST crash and restart process for unhandled Programmer Errors
- Distinctive: line 60
MUST standardize all HTTP error responses to RFC 7807 format
- Distinctive: line 61
MUST log full stack traces for 5xx errors
- Distinctive: line 62
MUST log only message and context for 4xx errors
- Distinctive: line 63
MUST sanitize all error responses (no DB details, SQL, stack traces)
- Distinctive: line 64
MUST NEVER throw string literals (always throw Error objects)
- Distinctive: line 65
MUST distinguish between Operational and Programmer errors
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Error Handling Architecture
Purpose
Uncaught exceptions crash servers. Leaked errors expose vulnerabilities. This skill creates a central, robust pipeline for capturing, categorizing, logging, and responding to failures without leaking sensitive data, ensuring system resilience and debugging capability.
When to use
- Setting up a new backend service
- Refactoring code with excessive uncoordinated
try/catchblocks - Standardizing API error responses across a team
- Implementing a new microservice with shared error handling
When NOT to use
- Client-side error handling (different context)
- Monitoring/alerting setup (separate concern, use Logging & Observability instead)
- Specific framework error documentation
Inputs required
- Existing backend service codebase
- Framework error handling capabilities (Express middleware, Django signals, etc.)
- Logging infrastructure setup
Workflow
- Define Error Classes: Create base
AppErrorclass withstatusCode,isOperationalflag, and metadata - Categorize Errors: Distinguish Operational (bad input, network) from Programmer (null ptr, logic bug)
- Centralize Middleware: Add framework-level error handler to catch ALL exceptions globally
- Log Appropriately: Full stack for 5xx errors; metadata only for 4xx errors
- Sanitize Output: Strip stack traces and internal details before sending to client
- Crash on Programmer Error: Unhandled programmer errors MUST crash and restart the process
- Test Error Paths: Verify error handling works for all failure scenarios
Rules
- MUST NEVER silently swallow exceptions (
catch(e) {}) - MUST crash and restart process for unhandled Programmer Errors
- MUST standardize all HTTP error responses to RFC 7807 format
- MUST log full stack traces for 5xx errors
- MUST log only message and context for 4xx errors
- MUST sanitize all error responses (no DB details, SQL, stack traces)
- MUST NEVER throw string literals (always throw Error objects)
- MUST distinguish between Operational and Programmer errors
Anti-patterns
- Throwing Strings:
throw "User not found"(throw Error objects always) - Leaking DB Details: Sending raw SQL constraint violation messages to client
- Silent Catching:
catch(e) {}with no logging or action - 200 OK for Errors: HTTP 200 with
{ error: true }payload - Generic Messages: "Something went wrong" (unhelpful for debugging)
- Unhandled Promises: Async functions without catch handlers
Failure conditions
- Unhandled exception occurs (process crashes without logging)
- Error response includes stack trace or internal details
- Silent exception swallowing (error never logged)
- HTTP 200 returned for failed requests
- Database constraint violation message sent to client
Validation checklist
- All errors are Error objects (never strings)
- Global error middleware catches all exceptions
- Error responses use RFC 7807 format with
type,title,detail,status - Stack traces never sent to client
- Sensitive data (DB queries, credentials) never in error responses
- Operational errors return appropriate 4xx status codes
- Programmer errors crash and restart
- Full stack traces logged for 5xx errors
- Request context (user ID, correlation ID) included in logs
- No
catch(e) {}blocks with no action
Output format
- Error Object: Contains
statusCode,message,isOperationalflag, and optionalcontext - Response Format: RFC 7807 Problem Details JSON
- Log Format: Structured JSON with timestamp, level, context, stack trace (for 5xx)
- Process Behavior: Unhandled programmer errors crash; operational errors continue
Security considerations
- Error messages MUST NOT leak internal architecture (DB names, file paths, versions)
- Stack traces MUST NEVER be sent to clients (log internally only)
- Database error messages MUST be wrapped (never expose raw constraints)
- Sensitive user data MUST NOT appear in error logs (sanitize before logging)
- Error pages MUST NOT reveal system information
Agent execution notes
- Agent MAY: Create error classes, add global error middleware, sanitize responses, implement error logging
- Agent MUST NEVER: Throw strings, catch exceptions silently, leak stack traces, return 200 for errors
- Agent MUST ASK: Before changing error categorization, before modifying global error handler
- Agent MUST VALIDATE: All errors are Error objects, no stack traces in responses, proper categorization
Example
❌ Anti-pattern (Silent catching, leaking details, wrong status):
app.get('/users/:id', async (req, res) => {
try {
const user = await db.query(`SELECT * FROM users WHERE id = ${req.params.id}`);
res.json(user);
} catch(e) {
// ANTI-PATTERN: silent catch
res.json({ status: 'error', message: e.message }); // ANTI-PATTERN: 200 OK
// ANTI-PATTERN: leaking SQL details
}
});✅ Correct pattern (Centralized, sanitized, proper codes):
// 1. Define error class
class AppError extends Error {
constructor(statusCode, message, isOperational = true) {
super(message);
this.statusCode = statusCode;
this.isOperational = isOperational;
}
}
// 2. Route handler
app.get('/users/:id', async (req, res, next) => {
try {
const user = await db.query('SELECT * FROM users WHERE id = ?', [req.params.id]);
if (!user) {
return next(new AppError(404, 'User not found'));
}
res.json(user);
} catch (err) {
next(err); // Pass to global handler
}
});
// 3. Global error middleware
app.use((err, req, res, next) => {
// Log with context
logger[err.isOperational ? 'warn' : 'error']({
message: err.message,
statusCode: err.statusCode,
stack: err.stack,
requestId: req.id,
userId: req.user?.id
});
// Crash on programmer error
if (!err.isOperational) {
process.exit(1);
}
// Sanitized response
res.status(err.statusCode || 500).json({
type: 'https://api.example.com/errors/app-error',
title: err.statusCode === 404 ? 'Not Found' : 'Server Error',
detail: err.isOperational ? err.message : 'Internal server error',
status: err.statusCode || 500
});
});Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

