error-handling-patterns
Skill0 starsChanged 3 days agoMITView on GitHub
Error handling for Node.js backends (Express 4/5, Fastify, NestJS, Hono) - async route errors, a typed error hierarchy, one central error handler returning RFC 9457 problem+json, last-resort process handlers (unhandledRejection, uncaughtException) with graceful exit, and operational vs programmer errors. Includes a checker for empty catch blocks, .catch(() => {}), throw of strings, async Promise executors, Express 4 async handlers without try/catch or a wrapper, missing error middleware, uncaughtException handlers that never exit, and internal error messages sent to clients, plus a drop-in errors.ts. Use when requests hang or crash the process, errors leak to clients, the user asks for consistent API error responses or problem details, or reviews try/catch and async code in a Node.js API.
- Installs packages
28 other projects use a version of this.
Adopted by
Most recently taken up by
- Rain-kl/OpenFlaretheir own version, first seen Nov 30, 2026
- gromov0737/skillstheir own version, first seen Nov 29, 2026
- autohandai/community-skillstheir own version, first seen Nov 29, 2026
- JuankCadavid/akili-specstheir own version, first seen Nov 25, 2026
- The-AIOS/aiostheir own version, first seen Nov 17, 2026
- AtilaMedeiros/skillstheir own version, first seen Nov 16, 2026
Used with
Projects with it also use 0-template, github-actions-builder and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
JayRHaSkill0-template
Template for creating a new Agent Skill. Copy this folder, rename it to your skill's kebab-case name, and fill in every section. Use this as the starting point whenever you author a new skill for the AgentSkills library.
Also in 3 projects that use this
JayRHaSkillgithub-actions-builder
Builds reliable, fast, and secure GitHub Actions CI/CD workflows with dependency caching, build matrices, scoped secrets, concurrency control, and reusable/composite workflows. Use this skill when the user asks to "create a GitHub Actions workflow", "set up CI", "add CI/CD", "fix a flaky/slow GitHub Actions pipeline", "add a build matrix", "cache dependencies in CI", "write a reusable workflow", "configure deployment with environments and secrets", or mentions files under .github/workflows.
Also in 3 projects that use this
xmqywxSkillmeeting-summarizer
Transform meeting transcripts into structured summaries with action items, decisions, follow-ups, and efficiency analysis. Works with any meeting format.
Also in 3 projects that use this
pbc-osSkillsecrets-manager
Set up and configure cloud secrets management for your AI agent. Guides users through platform selection (GCP, AWS, Azure, 1Password, Doppler, HashiCorp Vault), account setup, CLI configuration, and secure credential storage.
Also in 3 projects that use this
zwjbendnSkillhabit-builder
Designs and manages healthy habits for sustainable weight loss through lifestyle change. Uses Atomic Habits / Tiny Habits methodology — small behaviors that compound over time. Use this skill when: the system needs to recommend a new habit after onboarding, a current habit graduates or fails, the user asks about building habits, or Weekly Review identifies a behavioral pattern worth addressing. Also use when evaluating habit progress, deciding when a habit has "graduated," or handling a restart after the user falls off. This skill does not send its own reminders — habit check-ins are woven into meal conversations managed by Notification Composer. This skill owns the check-in logic (when, how often, tone); Notification Composer provides the conversation vehicle.
Also in 3 projects that use this
- +7 more from JayRHa
Other versions28 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 28
- Rain-kl/OpenFlare★ 305same name
- The-AIOS/aios★ 130same name
- farming-labs/fm-skills★ 35same name
- jaskirat1616/grok-skills★ 22same name
- autohandai/community-skills★ 14same name
- JayRHa/agent-skills★ 12same name
- JayRHa/AgentSkills★ 12same name
- JuankCadavid/akili-specs★ 12same name
- xfstudio/skills★ 9same name
- KhaledSaeed18/dotclaude★ 7same name
18 more not listed
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 repository8 other files it gives its agents.
- AGENTS.mdAGENTS.md
- api-performanceSkill
- background-jobsSkill
- env-configSkill
- logging-and-tracingSkill
- node-deploySkill
- node-security-reviewSkill
- package-json-auditSkill
The file
We split this skill into the rules it gives an agent
1 rule. 0 are common, 1 is distinctive, and 0 are very specific to this project.
0
Common
Most of the 27 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 65
Do not catch only to log and rethrow at every layer.
“Common” is measured: kept by at least 6 in 10 of the 27 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Error handling patterns
Goal: every error ends up in exactly one place that logs it once, maps it to a status code
and returns a consistent application/problem+json body, and the process exits cleanly
when its state is unknown.
Paths below are relative to this skill's folder (in Claude Code: ${CLAUDE_SKILL_DIR}).
When to use
- Requests hang on errors, or one bad request crashes the server
- "Make our API errors consistent", "add problem details", "global error handler"
- Reviewing
try/catch, promises,asynchandlers,process.on(...)code - Migrating Express 4 to 5 (async error behaviour changes)
When not to use
- What and how to log (fields, redaction, tracing):
logging-and-tracing - Retrying failed background jobs:
background-jobs - Shutdown on SIGTERM and health checks:
node-deploy(this skill covers fatal errors only)
Workflow
- Identify the framework and version. Express major matters most:
- Express 5: a rejected promise in a handler goes to the error middleware.
- Express 4: it does not; the request hangs and Node logs an unhandled rejection.
Fix by upgrading,
require('express-async-errors')once at startup, or wrapping. - Fastify, NestJS, Hono: async errors reach the framework handler.
- Run the checker (read-only).
Express major is read from the nearestpython3 scripts/check_error_handling.py src python3 scripts/check_error_handling.py src --json --express-major 4package.json. Exit 1 = findings at or above--fail-on(defaultmedium). - Fix in this order:
express.async_unhandled(hanging requests / crashes)process.handler_no_exit, then add the last-resort handlers if missingexpress.no_error_handler/ central handler for the frameworkcatch.empty,promise.async_executor,throw.literal,error.raw_to_client
- Introduce the pattern (show the diff first):
- Copy assets/errors.ts:
AppErrorsubclasses (NotFoundError,ValidationError,ConflictError,UnauthorizedError,ForbiddenError) andtoProblem()which maps any thrown value to RFC 9457 fields. - Register one central handler per framework from references/framework-handlers.md.
- Validation errors (zod, class-validator, Fastify schema) become 400/422 with an
errorsarray; unknown errors become 500 with a genericdetailand the request id.
- Copy assets/errors.ts:
- Decision rules (more in references/principles.md):
- Operational errors (not found, invalid input, timeout, upstream 503): handle, map to 4xx/5xx.
- Programmer errors (TypeError, undefined is not a function): let them reach the handler, return 500, alert; do not try to "recover".
uncaughtException: log fatal, close servers,process.exit(1). Never continue.- Wrap with cause:
throw new AppError('charge failed', { cause: err }). - Do not catch only to log and rethrow at every layer; log once at the edge.
- Verify: re-run the checker; add tests that hit a missing id (404 problem+json), invalid body (400/422), and a thrown bug (500 without stack in the body).
Output
Error handling: api (Express 4.21) - 2 high, 3 medium
HIGH src/routes/users.js:12 async handler without try/catch -> requests hang on DB errors
fix: npm i express-async-errors and require it first, or upgrade to Express 5
MED src/server.js:40 uncaughtException handler never exits -> log + exit(1)
MED src/app.js:3 no error middleware -> add problemHandler (diff below)
Example response after the change:
HTTP/1.1 404 Content-Type: application/problem+json
{"type":"https://example.com/problems/not-found","title":"Not Found","status":404,
"detail":"User 42 not found","instance":"/users/42","requestId":"9f1c..."}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.

