agentleFS
komlukkomluk/scaffolding/skills/error-handling/SKILL.md

error-handling

Skill16 starsChanged 5 days agoMITView on GitHub

Consistent error handling across frontend and backend layers. TRIGGER when: implementing error boundaries, exception handlers, or try/catch blocks. SKIP: shaping HTTP error response bodies (use api-design); logging the error (use logging-standards). (Examples in React + Python.)

80 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use convention-learner, caching 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.
  • codewithmukeshSkill

    convention-learner

    Detects and enforces project-specific coding conventions by analyzing existing codebase patterns. Learns naming conventions, folder structure, test organization, and coding style from the existing code. Load when: "conventions", "coding standards", "project patterns", "enforce style", "detect patterns", "learn conventions", "code consistency".

    Also in 3 projects that use this

  • wpankSkill

    caching

    Caching strategies, invalidation, eviction policies, HTTP caching, distributed caching, and anti-patterns. Use when designing cache layers, choosing eviction policies, debugging stale data, or optimizing read-heavy workloads.

    Also in 6 projects that use this

  • diego-tobalinaSkill

    logging

    Logging best practices for Java (SLF4J/Logback) and Node.js (Winston/Pino). Use for structured logging, log levels, and avoiding sensitive data exposure.

    Also in 12 projects that use this

  • codewithmukeshSkill

    opentelemetry

    OpenTelemetry observability for .NET 10 applications. Covers traces, metrics, and logs using the OpenTelemetry SDK with OTLP export. Includes custom ActivitySource, IMeterFactory metrics, resource configuration, and Aspire Dashboard integration. Load this skill when setting up distributed tracing, custom metrics, OTLP export, or when the user mentions "OpenTelemetry", "OTLP", "traces", "spans", "Activity", "ActivitySource", "metrics", "IMeterFactory", "Meter", "Counter", "Histogram", "Gauge", "telemetry", "observability", "distributed tracing", "OTEL", or "Aspire Dashboard".

    Also in 3 projects that use this

  • MovGP0Skill

    modern-csharp

    Modern C# style guidance for Bendex and MicroSea code changes, including primary constructors, expression-bodied members, var usage, target-typed new, lambdas, and pattern matching.

    Also in 3 projects that use this

  • MicrosoftSkill

    resilience

    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 4 projects that use this

The file

We split this skill into the rules it gives an agent

11 rules. 0 are common, 9 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 64 edited versions we read keep these.

  • 9

    Distinctive

    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
  1. Very specific:

    Create base AppException class for all application errors

    line 39
  2. Distinctive:

    Never expose internal details to clients

    line 42
  3. Very specific:

    Use SCREAMING_SNAKE_CASE

    line 68
  4. Distinctive:

    Don't blame the user

    line 91
  5. Distinctive:

    Never return stack traces in production

    line 102
  6. Distinctive:

    Don't catch exceptions you can't handle

    line 106
  7. Distinctive:

    Always re-throw or wrap caught exceptions

    line 107
  8. Distinctive:

    Add jitter to prevent thundering herd

    line 144
  9. Distinctive:

    Use specific exception types

    line 165
  10. Distinctive:

    Use circuit breaker for external services

    line 170
  11. Distinctive:

    Use exceptions for control flow

    line 176

“Common” is measured: kept by at least 6 in 10 of the 64 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Error Handling Skill

Purpose

Standards for consistent error handling across frontend and backend layers (examples in React + Python).

Auto-Invoke Triggers

  • Implementing exception handling
  • Creating custom exceptions
  • Handling API errors
  • Implementing retry logic
  • Designing user-facing error messages

Error Categories

CategoryHTTP CodeUser ActionLog Level
Validation400Show field errorsWARN
Authentication401Redirect to loginWARN
Authorization403Show permission deniedWARN
NotFound404Show not found messageINFO
Conflict409Show conflict detailsWARN
RateLimit429Show retry-afterWARN
ExternalService502Show fallback/retry optionERROR
Internal500Show generic errorERROR
Critical500Show maintenance pageCRITICAL

Exception Hierarchy Design

Principles

  • Create base AppException class for all application errors
  • Extend with specific exception types per category
  • Include: code, message, status code, details (optional)
  • Never expose internal details to clients

Required Exception Types

  1. ValidationException - Invalid input data
  2. AuthenticationException - Auth token invalid/expired
  3. AuthorizationException - User lacks permission
  4. NotFoundException - Resource doesn't exist
  5. ConflictException - Resource state conflict
  6. RateLimitException - Too many requests
  7. ExternalServiceException - Third-party failure

Error Response Format

Standard Structure

{
  "code": "ERROR_CODE",
  "message": "Human-readable description",
  "details": { "field": ["error1", "error2"] },
  "correlationId": "abc-123"
}

Error Codes Convention

  • Use SCREAMING_SNAKE_CASE
  • Be specific: USER_NOT_FOUND not NOT_FOUND
  • Group by domain: AUTH_TOKEN_EXPIRED, AUTH_INVALID_CREDENTIALS

Frontend Error Handling

Principles

  • Catch errors at API client level
  • Transform to typed error objects
  • Display user-friendly messages
  • Log for debugging (not in production)

Error Boundary Rules

  • Wrap major UI sections
  • Provide fallback UI
  • Log errors to monitoring service
  • Allow recovery when possible

User Message Guidelines

  • Be helpful, not technical
  • Suggest actions user can take
  • Don't blame the user
  • Include support contact for critical errors

Backend Error Handling

Global Exception Handler

  • Catch all unhandled exceptions
  • Log with full context (path, method, user, correlation ID)
  • Return standardized error response
  • Never return stack traces in production

Exception Handling Rules

  • Throw specific exceptions, catch specific exceptions
  • Don't catch exceptions you can't handle
  • Always re-throw or wrap caught exceptions
  • Log at the boundary, not deep in code

What to Log

  • Error type and message
  • Request path and method
  • User ID (if authenticated)
  • Correlation ID
  • Stack trace (for unexpected errors)

What NOT to Log

  • Passwords or tokens
  • Full request/response bodies with PII
  • Credit card numbers
  • Personal data (GDPR)

Retry Logic Standards

When to Retry

  • Network timeouts
  • 5xx server errors (external services)
  • Rate limit (with backoff)
  • Connection refused

When NOT to Retry

  • 4xx client errors (except 429)
  • Validation errors
  • Authentication errors
  • Non-idempotent operations (without idempotency key)

Retry Configuration

  • Max attempts: 3
  • Initial delay: 1 second
  • Backoff multiplier: 2 (exponential)
  • Max delay: 30 seconds
  • Add jitter to prevent thundering herd

Circuit Breaker Pattern

Configuration

  • Failure threshold: 5 failures
  • Recovery timeout: 30 seconds
  • Half-open max requests: 3

States

  1. Closed - Normal operation, requests pass through
  2. Open - Failures exceeded threshold, requests fail fast
  3. Half-Open - Testing if service recovered

Best Practices

DO

  • Use specific exception types
  • Include correlation IDs in all errors
  • Log errors with context
  • Return user-friendly messages
  • Implement retry for transient failures
  • Use circuit breaker for external services

DON'T

  • Catch generic Exception without re-throwing
  • Log sensitive data
  • Return stack traces to clients
  • Use exceptions for control flow
  • Ignore errors silently
  • Retry non-idempotent operations blindly

Quality Checklist

  • All API endpoints return consistent error format
  • Custom exceptions extend base exception class
  • Global exception handler catches all unhandled exceptions
  • Errors logged with appropriate level and context
  • User messages helpful but don't leak internals
  • Retry logic for external service calls
  • Circuit breaker for cascading failure protection
  • Correlation IDs tracked through entire request

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.