agentleFS
Vimalk0703Vimalk0703/shipworthy/skills/quality/error-handling-patterns/SKILL.md

error-handling-patterns

Skill6 starsChanged 8 months agoMITView on GitHub

Structured error types, recovery strategies, and boundary-aware error handling. Prevents raw string errors, leaked stack traces, and silent failures.

16 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use python-project-structure and git-commit.

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.
  • Aver005Skill

    python-project-structure

    Python project organization, module architecture, and public API design. Use when setting up new projects, organizing modules, defining public interfaces with __all__, or planning directory layouts.

    Also in 3 projects that use this

  • GitHubSkill

    git-commit

    Execute git commit with conventional commit message analysis, intelligent staging, and message generation. Use when user asks to commit changes, create a git commit, or mentions "/commit". Supports: (1) Auto-detecting type and scope from changes, (2) Generating conventional commit messages from diff, (3) Interactive commit with optional type/scope/description overrides, (4) Intelligent file staging for logical grouping

    Also in 3 projects that use this

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 15 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
  1. Distinctive:

    Every catch block must implement one of:

    line 42

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

Core Principles

  1. Errors are data, not strings — use structured error types with codes, messages, and context
  2. Handle at boundaries — catch at architectural boundaries (API, service, data layer), not everywhere
  3. User-facing errors are safe — never expose stack traces, internal paths, or implementation details
  4. Errors are loggable — every error carries enough context to debug without reproducing
  5. Recovery is explicit — every catch block states its recovery strategy

Structured Error Pattern

class AppError extends Error {
  constructor(
    public code: string,
    message: string,
    public statusCode: number = 500,
    public context?: Record<string, unknown>
  ) {
    super(message);
    this.name = 'AppError';
  }
}
throw new AppError('USER_NOT_FOUND', 'User does not exist', 404, { userId });

Boundary Error Handling

  • API Layer: Catch all, map to HTTP status, return safe JSON, log full error with correlation ID
  • Service Layer: Catch specific expected errors, add context, re-throw as AppError
  • Data Layer: Catch DB-specific errors, translate to domain errors (duplicate key → CONFLICT)

Recovery Strategies

Every catch block must implement one of:

  1. Retry — transient failures (network, rate limits). Exponential backoff.
  2. Fallback — degrade gracefully (cache, default value)
  3. Propagate — re-throw with added context for the next boundary
  4. Fail fast — unrecoverable. Log, clean up, terminate the operation.

Anti-Patterns

  • catch (e) {} — silent swallowing. NEVER.
  • catch (e) { console.log(e) } — logged but not handled. What's the recovery?
  • Catching too broadly at the wrong layer
  • Wrapping every function call in try/catch

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.