Skip to content

feat: add custom error classes for better error handling#16

Open
alobroke wants to merge 1 commit intobug0inc:mainfrom
alobroke:feat/playwright-compat-layer
Open

feat: add custom error classes for better error handling#16
alobroke wants to merge 1 commit intobug0inc:mainfrom
alobroke:feat/playwright-compat-layer

Conversation

@alobroke
Copy link
Copy Markdown

@alobroke alobroke commented Apr 3, 2026

Closes #9

What

Creates src/errors.ts with a custom error hierarchy for Passmark.

New classes:

  • PassmarkError — base class, all errors extend this. Has a code property for programmatic identification
  • StepExecutionError — step failed during AI or cached execution. Includes stepDescription field
  • AIModelError — AI provider/model failure or unknown provider
  • CacheError — Redis/cache failures (ready for future use as Redis handling grows)
  • ConfigurationError — missing API keys or environment variables
  • ValidationError — invalid inputs (missing script content, missing executionId/projectId)

Why

All errors were generic Error instances, making it impossible for users to programmatically distinguish between different failure types. Now users can do:

import { StepExecutionError, ConfigurationError } from "passmark";

try {
  await runSteps({ ... });
} catch (e) {
  if (e instanceof StepExecutionError) {
    console.log("Failed step:", e.stepDescription);
    console.log("Error code:", e.code); // "STEP_EXECUTION_FAILED"
  }
  if (e instanceof ConfigurationError) {
    // missing API key — show setup instructions
  }
}

Changes

  • src/errors.ts — new file with all error classes
  • src/index.ts — uses StepExecutionError and ValidationError
  • src/models.ts — uses ConfigurationError and AIModelError
  • src/data-cache.ts — uses ConfigurationError and ValidationError
  • src/email.ts — uses ConfigurationError and AIModelError
  • All error classes exported from the public API

- Add PassmarkError base class with error code property
- Add StepExecutionError for step execution failures (with stepDescription field)
- Add AIModelError for AI provider/model failures
- Add CacheError for Redis/cache failures (ready for future use)
- Add ConfigurationError for missing env vars and config
- Add ValidationError for invalid inputs (missing scripts, placeholders)
- Replace all generic Error instances across index.ts, models.ts, data-cache.ts, email.ts
- Export all error classes from public API so users can do instanceof checks

Closes bug0inc#9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create custom error classes for better error handling

1 participant