error-handling
Skill1 starsChanged 2 months agoMITView on GitHub
Use when building error recovery, handling exceptions, designing error flows, or implementing logging for errors — covers retry, circuit-breaker, error wrapping, structured logging.
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 58 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 37
Add context as errors propagate—original error + where + why.
“Common” is measured: kept by at least 6 in 10 of the 58 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 & Recovery
Structured approaches to errors, recovery, and observability. Never silently hide errors.
Core Patterns
1. Explicit Errors (Always)
Return errors as values or raise them; never ignore them.
# ✅ Good: Explicit handling
try:
user = parse_user_data(raw)
except json.JSONDecodeError as e:
# Never log the raw payload — it can carry passwords/PII. Log a
# bounded, redaction-safe summary instead.
logger.error("Invalid user JSON", extra={"error": str(e), "payload_length": len(raw)})
return None
# ❌ Bad: Silent failure
try:
parse_user_data(raw)
except:
pass # User data silently ignored2. Error Wrapping (Across Boundaries)
Add context as errors propagate—original error + where + why.
# ✅ Python: Preserve cause
try:
return repository.find(user_id)
except DatabaseError as e:
raise UserNotFoundError(f"find user {user_id}") from e
# ✅ Go: Wrap with context
user, err := repo.Find(userID)
if err != nil {
return nil, fmt.Errorf("find user %s: %w", userID, err)
}3. Error Classification
Decide recovery strategy based on error type.
def classify_error(error):
if isinstance(error, (ConnectionError, TimeoutError)):
return "transient" # Retry
elif isinstance(error, (ValueError, KeyError)):
return "validation" # Reject, don't retry
else:
return "unknown"
# Transient → retry with backoff
# Validation → log and fail
# Fatal → panic4. Retry with Backoff (for Transient Errors)
Retry flaky operations; don't retry permanent failures.
import time
def retry(func, max_attempts=3, backoff_base=2):
"""Retry with exponential backoff."""
for attempt in range(max_attempts):
try:
return func()
except (ConnectionError, TimeoutError) as e:
if attempt < max_attempts - 1:
wait_time = backoff_base ** attempt
logger.warning(f"Retry {attempt + 1}/{max_attempts}, waiting {wait_time}s")
time.sleep(wait_time)
else:
raise
except (ValueError, KeyError):
raise # Don't retry validation errors
# Usage
user = retry(lambda: fetch_user(user_id), max_attempts=3)5. Circuit Breaker (for Cascading Failures)
Fail fast when a service is down; stop hammering it.
class CircuitBreaker:
CLOSED, OPEN, HALF_OPEN = "closed", "open", "half_open"
def __init__(self, failure_threshold=5, timeout=60):
self.failures = 0
self.threshold = failure_threshold
self.timeout = timeout
self.state = self.CLOSED
self.last_failure = None
def call(self, func, *args, **kwargs):
if self.state == self.OPEN:
if time.time() - self.last_failure > self.timeout:
self.state = self.HALF_OPEN
else:
raise RuntimeError("Circuit is OPEN")
try:
result = func(*args, **kwargs)
self.failures = 0 # Success: reset
self.state = self.CLOSED
return result
except Exception as e:
self.failures += 1
self.last_failure = time.time()
if self.failures >= self.threshold:
self.state = self.OPEN
raise6. Fallback (Default When Primary Fails)
Provide sensible default when operation fails.
def get_user_with_fallback(user_id):
"""Try cache → database → guest fallback."""
try:
return cache.get(user_id)
except CacheError:
pass
try:
user = database.find(user_id)
cache.set(user_id, user) # Warm cache
return user
except DatabaseError as e:
logger.error("Database down", extra={"error": str(e)})
return User.guest() # Fallback7. Structured Error Logging (Always)
Log errors with full context, not just the message.
# ❌ Bad: Lost context
logger.error(str(error))
# ✅ Good: Full context
logger.error("Failed to fetch user", extra={
"user_id": user_id,
"operation": "fetch",
"error_type": type(error).__name__,
"error_message": str(error),
"retry_count": attempt,
})Decision Tree
Error occurs
├─ Catch it?
│ ├─ Yes → Can recover?
│ │ ├─ Yes → Transient? (network, timeout, rate limit)
│ │ │ ├─ Yes → Retry with backoff + circuit breaker
│ │ │ └─ No → Fallback or fail fast
│ │ └─ No → Log + re-raise
│ └─ No → Let it propagate up
└─ Always wrap with context (where + why)Common Mistakes
| Mistake | Fix |
Catching Exception broadly | Catch specific errors you can handle |
| Ignoring errors silently | Log errors with full context |
| No backoff on retry | Exponential backoff: 1s, 2s, 4s, 8s… |
| Retrying permanent errors | Classify errors first; don't retry 404, 401 |
| Lost error chain | Preserve cause: from e (Python), %w (Go) |
References
This file is self-contained for day-to-day use. Deeper reference (needs the full harness checkout, not just this skill):
- Full guide:
patterns/error-handling/README.md - Logging:
patterns/logging/LOGGING_STANDARDS.md
Other versions72 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 72
- microsoft/data-formulator★ 17ksame name
- epicenter-md/epicenter★ 4.8ksame name
- EpicenterHQ/epicenter★ 4.8ksame name
- NVIDIA-NeMo/RL★ 2.1ksame name
- software-mansion/react-native-executorch★ 1.8ksame name
- CloudAI-X/claude-workflow★ 1.4ksame name
- CloudAI-X/claude-workflow-v2★ 1.4ksame name
- alchemyplatform/aa-sdk★ 321same name
- Resgrid/Core★ 229same name
- DevelopersGlobal/ai-agent-skills★ 216same name
62 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.
Used alongsideProjects with it also use caching, type-safety and 8 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.
zebbernSkillcaching
Caching strategies — invalidation, TTL guidelines, cache keys, cache layers, and when not to cache. Use when implementing or reviewing caching logic.
Also in 5 projects that use this
WelluxSkilltype-safety
Add or fix type annotations and enforce strict type safety. Invoke for: "add types", "type annotation", "TypeScript types", "Python type hints", "mypy", "tsc strict", "type errors", "any type", "unsafe cast", "missing types", "type this".
Also in 3 projects that use this
dbtlrSkilldependencies
Use when adding, evaluating, or updating Rust crate dependencies. Also use when considering whether to implement something yourself vs pulling in a library.
Also in 3 projects that use this
MicrosoftSkillresilience
Apply resilience patterns (retry, backoff, circuit breaking) when writing or reviewing code that makes outbound HTTP/REST calls, database operations, or any I/O that can experience transient failures. Use this skill when: (1) writing new code that calls external services or APIs, (2) reviewing code that uses fetch, HTTP clients, or service-to-service calls, (3) adding queue consumers or workers that interact with remote systems, (4) debugging intermittent failures in production.
Also in 3 projects that use this
OpenAISkillauth
Authentication integration guidance — Clerk (native Vercel Marketplace), Descope, and Auth0 setup for Next.js applications. Covers middleware auth patterns, sign-in/sign-up flows, and Marketplace provisioning. Use when implementing user authentication.
Also in 5 projects that use this
JohnJBorenSkillci-cd
CI/CD pipeline design, GitHub Actions, testing automation, and deployment strategies
Also in 7 projects that use this
In this repository77 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/accessibility.mdcCursor rule
- .cursor/rules/agentharness-router.mdcCursor rule
- .cursor/rules/agentic-loops.mdcCursor rule
- .cursor/rules/api-design.mdcCursor rule
- .cursor/rules/audit-review-followup.mdcCursor rule
- .cursor/rules/big-work-plan-review.mdcCursor rule
- .cursor/rules/branching.mdcCursor rule
- .cursor/rules/clean-architecture.mdcCursor rule
- .cursor/rules/code-review-api.mdcCursor rule
- .cursor/rules/code-review-db.mdcCursor rule
- .cursor/rules/code-review.mdcCursor rule
- .cursor/rules/code-review-ui.mdcCursor rule
- .cursor/rules/committing.mdcCursor rule
- .cursor/rules/database-conventions.mdcCursor rule
- .cursor/rules/dependency-audit.mdcCursor rule
- .cursor/rules/dependency-injection.mdcCursor rule
- .cursor/rules/design-patterns.mdcCursor rule
- .cursor/rules/docker-conventions.mdcCursor rule
- .cursor/rules/error-handling.mdcCursor rule
- .cursor/rules/file-placement-policy.mdcCursor rule
- .cursor/rules/github-issue-triage.mdcCursor rule
- .cursor/rules/go-conventions.mdcCursor rule
- .cursor/rules/harness-feedback.mdcCursor rule
- .cursor/rules/logging.mdcCursor rule
- .cursor/rules/multi-agent-coordination.mdcCursor rule
- .cursor/rules/mutation-testing.mdcCursor rule
- .cursor/rules/performance-profiling.mdcCursor rule
- .cursor/rules/planning-with-files.mdcCursor rule
- .cursor/rules/port-agent-config.mdcCursor rule
- .cursor/rules/project-bootstrap.mdcCursor rule
- .cursor/rules/python-conventions.mdcCursor rule
- .cursor/rules/react-best-practices.mdcCursor rule
- .cursor/rules/refactoring.mdcCursor rule
- .cursor/rules/requirements-clarification.mdcCursor rule
- .cursor/rules/security-review.mdcCursor rule
- .cursor/rules/solid-principles.mdcCursor rule
- .cursor/rules/testing.mdcCursor rule
- .cursor/rules/typescript-conventions.mdcCursor rule
- accessibilitySkill
- agentic-loopsSkill
- api-designSkill
- audit-review-followupSkill
- big-work-plan-reviewSkill
- branchingSkill
- clean-architectureSkill
- code-review-apiSkill
- code-review-dbSkill
- code-reviewSkill
- code-review-uiSkill
- committingSkill
- database-conventionsSkill
- dependency-auditSkill
- dependency-injectionSkill
- design-patternsSkill
- docker-conventionsSkill
- file-placement-policySkill
- github-issue-triageSkill
- The first 60 shown.
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.

