agentleFS
benshapyrobenshapyro/cadre-devkit-claude/skills/error-handler/SKILL.md

error-handler

Skill9 starsChanged 12 months agoMITView on GitHub

Provides battle-tested error handling patterns for TypeScript and Python. Use when implementing error handling, creating try/catch blocks, or handling exceptions.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 8 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈8

    Distinctive · estimate

    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:

    Never Swallow Errors: - Always log, re-throw, or handle explicitly

    line 20
  2. Distinctive:

    Typed Errors: - Use custom error classes for different failure types

    line 22
  3. Distinctive:

    Use custom error classes for different error types

    line 92
  4. Distinctive:

    Always clean up resources (use try/finally or context managers)

    line 97
  5. Distinctive:

    Add retry logic for transient failures

    line 98
  6. Distinctive:

    Test error paths (negative tests)

    line 99
  7. Distinctive:

    Use generic error messages without context

    line 105
  8. Distinctive:

    Use errors for control flow

    line 109

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 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.

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

Error Handler Skill

Implements robust error handling patterns that provide meaningful errors, graceful degradation, and proper logging.

Resources

For detailed code examples, see:

  • references/typescript-patterns.md - TypeScript/JavaScript patterns (Express, React)
  • references/python-patterns.md - Python patterns (FastAPI, Flask)

Core Principles

  1. Fail Fast, Fail Loudly - Catch errors early, make them visible
  2. Context is King - Include relevant information in error messages
  3. Never Swallow Errors - Always log, re-throw, or handle explicitly
  4. User-Friendly Messages - Show generic messages to users, log details server-side
  5. Typed Errors - Use custom error classes for different failure types

Quick Patterns

Custom Error Class (TypeScript)

export class AppError extends Error {
  constructor(
    message: string,
    public code: string,
    public statusCode: number = 500,
    public context?: Record<string, unknown>
  ) {
    super(message);
    this.name = this.constructor.name;
  }
}

// Specific types
export class ValidationError extends AppError {
  constructor(message: string, context?: Record<string, unknown>) {
    super(message, 'VALIDATION_ERROR', 400, context);
  }
}

export class NotFoundError extends AppError {
  constructor(resource: string, id: string) {
    super(`${resource} not found`, 'NOT_FOUND', 404, { resource, id });
  }
}

Custom Exception (Python)

class AppError(Exception):
    def __init__(self, message: str, code: str, status_code: int = 500, context: dict | None = None):
        super().__init__(message)
        self.message = message
        self.code = code
        self.status_code = status_code
        self.context = context or {}

class ValidationError(AppError):
    def __init__(self, message: str, context: dict | None = None):
        super().__init__(message, "VALIDATION_ERROR", 400, context)

Error Handling Pattern

async function fetchData(id: string): Promise<Data> {
  if (!id) throw new ValidationError('Invalid ID', { id });

  try {
    const data = await db.find(id);
    if (!data) throw new NotFoundError('Data', id);
    return data;
  } catch (error) {
    if (error instanceof AppError) throw error;
    throw new DatabaseError('Fetch failed', { id, originalError: error.message });
  }
}

Best Practices

DO

  • Use custom error classes for different error types
  • Include context in errors (but sanitize before sending to client)
  • Log errors with structured data (method, path, user ID, etc.)
  • Provide user-friendly error messages
  • Handle errors at appropriate levels (function, route, global)
  • Always clean up resources (use try/finally or context managers)
  • Add retry logic for transient failures
  • Test error paths (negative tests)

DON'T

  • Swallow errors silently (catch (e) {})
  • Leak sensitive information in error messages
  • Use generic error messages without context
  • Ignore promise rejections
  • Re-throw errors without adding context
  • Return errors as values when exceptions are better
  • Use errors for control flow

Error Response Format

{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Invalid input data",
    "details": [{ "field": "email", "message": "Invalid format" }]
  }
}

Remember: Good error handling prevents debugging nightmares and provides a better user experience.


Version

  • v1.1.0 (2025-12-05): Split into references (typescript-patterns.md, python-patterns.md)
  • v1.0.0 (2025-11-15): Initial version

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.