paralleldrive/aidd/aidd-error-causes

Claude Code and agent skill by paralleldrive/aidd

Trust tier 2
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

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.

Install

npx vskill@latest install paralleldrive/aidd/aidd-error-causes

SKILL.md

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

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
383
Repository forks
33
Repository npm downloads, 7 days
945
7-day trend score
46

Stars and forks are for the whole GitHub repository, not this skill alone. Downloads are for the repository's npm package. Refreshed 29 Apr 2026, 6 months ago.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/paralleldrive/aidd/aidd-error-causes/badge)](https://verified-skill.com/skills/paralleldrive/aidd/aidd-error-causes)

Something wrong with this skill or its page? Tell us.