Agent skill

Error Causes Handling

by paralleldrive in paralleldrive/aidd

Has your agent throw and catch JavaScript and TypeScript errors with the error-causes library, using named causes, preserved originals and routed handlers.

MITAuto-check passedDevelopment

Install Error Causes Handling

skills CLI
$ npx skills add paralleldrive/aidd --skill aidd-error-causes -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install paralleldrive/aidd aidd-error-causes --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/paralleldrive/aidd.git skills-src && mkdir -p .claude/skills && cp -r skills-src/ai/skills/aidd-error-causes .claude/skills/aidd-error-causes && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
aidd-error-causes
GitHub stars
384
Token cost
~1.1k tokens
SKILL.md length
245 words
Files
2
Skills in repo
35
Repo updated
First seen
Licence
MIT

At a glance

Has your agent throw and catch JavaScript and TypeScript errors with the error-causes library, using named causes, preserved originals and routed handlers.

  • Works in 7 steps: Always use createError instead of new… → Always include name and message in error… → Include code when the error needs… → …
  • Writing code that throws errors in a JavaScript or TypeScript project
  • SKILL.md covers Why Error Causes?, Import Statement, Basic Usage and Error Properties, plus 5 more sections
  • Needs API_KEY and MISSING_CONFIG_KEY

What it does

This rule tells the agent to use the error-causes library for all error handling in JavaScript and TypeScript, instead of plain new Error calls. Errors are created with createError and carry a name, a message, an optional code and any custom context. Handlers can then match on names rather than instanceof checks, which also keeps working across memory realms such as iframes.

Caught errors are re-thrown with the original kept as cause, factory functions validate their parameters with structured errors, and tests assert on the cause rather than only the message. For APIs with several error types, an errorCauses pattern defines every possible error in one place and routes them to handlers by name. The rule ends with a numbered list that includes always using createError and always providing name and message.

When your agent uses it

  • Writing code that throws errors in a JavaScript or TypeScript project
  • Wrapping a caught error while keeping the original as its cause
  • Defining the set of error types an API can return and routing them

Example prompts

  • “Replace the plain Error throws in config.js with createError and add codes.”
  • “Define the error types for our payments module with the errorCauses pattern.”
  • “Update this catch block to re-throw with the original error as cause and add a test for it.”

Requirements

  • The error-causes npm package

Workflow steps

7 steps, taken from the first numbered list in SKILL.md.

  1. Always use createError instead of new Error() for thrown errors
  2. Always include name and message in error metadata
  3. Include code when the error needs programmatic handling
  4. Preserve original errors using the cause property when re-throwing
  5. Add context with custom properties relevant to the error
  6. Test the cause property in error tests, not just the error message
  7. Define error types using errorCauses() for APIs with multiple error types

What it can do on your machine

Read from SKILL.md and the folder at commit 9a7c8e3. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are javascript).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names these keys or tokens, usually read from environment variables:

    • API_KEY
    • MISSING_CONFIG_KEY

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Error Causes Handling loads about 1.1k tokens when it runs. Until then it costs about 50 tokens; SKILL.md has 245 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~50
When it runs · the whole SKILL.md, loaded when a task matches
~1.1k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from paralleldrive/aidd at commit 9a7c8e3, republished under its MIT licence (© paralleldrive). 245 words, ~1,068 tokens.

Download SKILL.mdSave it as .claude/skills/aidd-error-causes/SKILL.md (or your agent's skills folder). This skill also uses 1 other file; get the full folder from GitHub.
name
aidd-error-causes
description
Use the error-causes library for structured error handling in JavaScript/TypeScript. Use when throwing errors, catching errors, defining error types, or implementing error routing.

Error Causes Rule

Use the error-causes library for all error handling in JavaScript/TypeScript code to enable structured error handling with named causes.

Why Error Causes?

  • Enables structured error handling with named causes instead of relying on instanceof checks
  • Works across memory realms (e.g., iframes) unlike instanceof
  • Provides consistent error metadata (name, code, message, cause)
  • Makes error handling explicit and self-documenting
  • Allows for automatic error routing based on error names

Import Statement

js
import { createError } from "error-causes";

Basic Usage

Instead of throwing plain errors:

js
// ❌ DON'T
throw new Error('Config key "API_KEY" is required');

Use createError with structured metadata:

js
// ✅ DO
throw createError({
  name: 'ConfigurationError',
  message: 'Required configuration key "API_KEY" is not defined',
  code: 'MISSING_CONFIG_KEY',
  requestedKey: 'API_KEY'
});

Error Properties

Always include these properties in createError:

  • name - Error name for matching (e.g., 'ValidationError', 'AuthenticationError')
  • message - Human-readable error message
  • code (optional) - Error code for programmatic handling
  • Custom properties (optional) - Any additional context relevant to the error

Wrapping Caught Errors

When catching and re-throwing errors, preserve the original error as cause:

js
try {
  await someOperation();
} catch (originalError) {
  throw createError({
    name: 'OperationError',
    message: 'Failed to perform operation',
    code: 'OPERATION_FAILED',
    cause: originalError  // Preserve original error
  });
}

Factory Validation Errors

For factory functions that validate parameters at creation time:

js
const createMiddleware = ({ requiredParam } = {}) => {
  if (!requiredParam) {
    throw createError({
      name: 'ValidationError',
      message: 'requiredParam is required',
      code: 'MISSING_REQUIRED_PARAM'
    });
  }

  return async ({ request, response }) => {
    // middleware implementation
  };
};

Testing Error Causes

In tests, verify the error's cause property:

js
let error;
try {
  functionThatThrows();
} catch (e) {
  error = e;
}

assert({
  given: 'invalid input',
  should: 'throw Error with cause',
  actual: error instanceof Error && error.cause !== undefined,
  expected: true
});

assert({
  given: 'invalid input',
  should: 'have correct error name',
  actual: error.cause.name,
  expected: 'ValidationError'
});

assert({
  given: 'invalid input',
  should: 'have correct error code',
  actual: error.cause.code,
  expected: 'MISSING_REQUIRED_PARAM'
});

Error Handler Pattern

For APIs that define multiple error types, use the errorCauses pattern:

js
import { errorCauses, createError } from "error-causes";

// Define all possible errors for your API
const [apiErrors, handleApiErrors] = errorCauses({
  NotFound: {
    code: 404,
    message: 'Resource not found'
  },
  ValidationError: {
    code: 400,
    message: 'Invalid input'
  },
  Unauthorized: {
    code: 401,
    message: 'Authentication required'
  }
});

const { NotFound, ValidationError, Unauthorized } = apiErrors;

// Throw errors
if (!resource) throw createError(NotFound);

// Handle errors with automatic routing
someAsyncCall()
  .catch(handleApiErrors({
    NotFound: ({ message }) => console.log(message),
    ValidationError: ({ message }) => console.log(message),
    Unauthorized: ({ message }) => redirect('/login')
  }));

Rules

  1. Always use createError instead of new Error() for thrown errors
  2. Always include name and message in error metadata
  3. Include code when the error needs programmatic handling
  4. Preserve original errors using the cause property when re-throwing
  5. Add context with custom properties relevant to the error
  6. Test the cause property in error tests, not just the error message
  7. Define error types using errorCauses() for APIs with multiple error types

© paralleldrive, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 1 other file in ai/skills/aidd-error-causes of paralleldrive/aidd.

  • SKILL.md
  • README.md

Open the folder on GitHubat commit 9a7c8e3

Compare with similar skills

Error Causes Handling next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Error Causes Handling compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Error Causes Handling this skillparalleldrive/aidd384—~1.1kAutomated safety check: PassMIT
Cross-Language Coding Standardszereight/gitlab-mcp2k1 repos~1.4kAutomated safety check: PassMIT
AWS Lambda Durable Functionsawslabs/agent-plugins912—~2.3kAutomated safety check: PassApache-2.0
Code Review ChecklistshareAI-lab/learn-claude-code78k5 repos~1.1kAutomated safety check: PassMIT
Install Anti-Slop Oxlint Rulesdmmulroy/anti-slop5.2k—~2.2kAutomated safety check: PassMIT
Generate Release Notesteambit/bit18k—~2.2kAutomated safety check: PassCustom licence

Similar skills

  • Shared reference for naming, function size, complexity and error handling rules that reviewer agents apply across TypeScript, Python, Go, Rust, Java, C# and Swift.

    2k GitHub starsUsed in 1 repo~1.4k tokens
    DevelopmentAuto-check passed
  • AWS Lambda Durable Functions

    awslabs/agent-plugins

    Official

    Build resilient, long-running, multi-step applications with AWS Lambda durable functions with automatic state persistence, retry logic, and orchestration for long-running executions.

    912 GitHub stars~2.3k tokensUpdated 2 days ago
    Backend & APIsAuto-check passed
  • Code Review Checklist

    shareAI-lab/learn-claude-code

    Reviews code against a five-part checklist covering security, correctness, performance, maintainability and testing, and reports findings in a fixed format.

    78k GitHub starsUsed in 5 repos~1.1k tokens
    DevelopmentAuto-check passed
  • Installs, updates or migrates the vendored anti-slop Oxlint plugin in a repository, keeping local rule changes and the plugin's license and provenance files.

    5.2k GitHub stars~2.2k tokensUpdated 27 days ago
    DevelopmentAuto-check passed
  • Generate comprehensive release notes for Bit from git commits and pull requests.

    18k GitHub stars~2.2k tokensUpdated yesterday
    DevelopmentAuto-check passed
  • Pnpm Engine

    teambit/bit

    Work on the pnpm Rust engine (@pnpm/napi, the pacquet crates) that bit install runs through.

    18k GitHub stars~1.9k tokensUpdated yesterday
    DevelopmentAuto-check passed

More from paralleldrive/aidd

All 35 skills in this repo
  • AIDD Skill Authoring Guide

    paralleldrive/aidd

    Guides creating, reviewing or refactoring AI-Driven Development skills so each one stays minimal, composable and named around a single clear function.

    384 GitHub stars~1.1k tokensUpdated 3 mo ago
    Auto-check passed
  • AIDD UI Layout Patterns

    paralleldrive/aidd

    Enforces a split of UI components into terminal and layout types, with layout components composing others through standard layout tokens, for cleaner structure and fewer re-renders.

    384 GitHub stars~562 tokensUpdated 3 mo ago
    Auto-check passed
  • Adobe Data ECS Plugin Rules

    paralleldrive/aidd

    Enforces @adobe/data/ecs practices when writing Database.Plugin definitions, including property order, plugin composition, services, components, resources and archetypes.

    384 GitHub stars~1.9k tokensUpdated 3 mo ago
    Auto-check passed
  • Teaches the saga pattern with call and put so network requests and side effects stay out of the logic and sagas can be tested without mocks.

    384 GitHub stars~587 tokensUpdated 3 mo ago
    Auto-check passed
  • Lit Element Authoring

    paralleldrive/aidd

    Rules for writing Lit elements in an AIDD project: binding elements on DatabaseElement, observed values, presentation components and action-style callbacks.

    384 GitHub stars~1.2k tokensUpdated 3 mo ago
    Auto-check passed
  • Epic Changelog Logger

    paralleldrive/aidd

    Adds completed epics to a changelog in reverse chronological order, one emoji-tagged line each, covering only significant user-facing work.

    384 GitHub stars~461 tokensUpdated 3 mo ago
    Auto-check passed

Categories

Questions about Error Causes Handling

What does Error Causes Handling do?

Has your agent throw and catch JavaScript and TypeScript errors with the error-causes library, using named causes, preserved originals and routed handlers. This rule tells the agent to use the error-causes library for all error handling in JavaScript and TypeScript, instead of plain new Error calls. Errors are created with createError and carry a name, a message, an optional code and any custom context.

When should I use Error Causes Handling?

Error Causes Handling fits situations like: writing code that throws errors in a JavaScript or TypeScript project; wrapping a caught error while keeping the original as its cause; defining the set of error types an API can return and routing them.

How do I install Error Causes Handling in Claude Code?

Run `npx skills add paralleldrive/aidd --skill aidd-error-causes -a claude-code`. Or copy the skill folder (ai/skills/aidd-error-causes in paralleldrive/aidd) into .claude/skills/aidd-error-causes in your project. Claude Code loads it when a task matches its description.

How do I install Error Causes Handling in Codex?

Run `npx skills add paralleldrive/aidd --skill aidd-error-causes -a codex`. Or copy the skill folder (ai/skills/aidd-error-causes in paralleldrive/aidd) into .agents/skills/aidd-error-causes in your project. Codex loads it when a task matches its description.

Can I use Error Causes Handling in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add paralleldrive/aidd --skill aidd-error-causes -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/aidd-error-causes, .gemini/skills/aidd-error-causes, .github/skills/aidd-error-causes and .opencode/skills/aidd-error-causes in your project.

What does Error Causes Handling need to run?

Going by SKILL.md and its folder, Error Causes Handling needs credentials named API_KEY and MISSING_CONFIG_KEY. Our summary lists: The error-causes npm package.

Does Error Causes Handling access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Error Causes Handling safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Error Causes Handling use?

Error Causes Handling is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Error Causes Handling use?

About 1.1k tokens (SKILL.md is roughly 4.3k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Error Causes Handling?

Skills that share tags, products or a category with Error Causes Handling: Cross-Language Coding Standards (zereight/gitlab-mcp, 2k stars), AWS Lambda Durable Functions (awslabs/agent-plugins, 912 stars), Code Review Checklist (shareAI-lab/learn-claude-code, 78k stars) and Install Anti-Slop Oxlint Rules (dmmulroy/anti-slop, 5.2k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Error Causes Handling?

paralleldrive (a GitHub organization) maintains it in paralleldrive/aidd, which has 384 GitHub stars. The repository holds 35 skills in this directory. The repository was last updated on June 12, 2026.

Source: paralleldrive/aidd on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.