搜索

PythonReactSEOPDF
GitHub Skill

tagged-error

Generate Effect TaggedError types for error handling. Use when adding new error types or improving error handling.

legacy3☆ 3 仓库 Stars0 仓库 Forks

安装与使用

请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。

查看来源 ↗使用指南

技能说明

Tagged Error Generator

Generate Effect Data.TaggedError types following project conventions.

Error Location

packages/wowlab-core/src/internal/errors/Errors.ts

Basic Error Template

import * as Data from "effect/Data";

export class MyError extends Data.TaggedError("MyError")<{
  readonly message: string;
  readonly cause?: unknown;
}> {}

Error with Context

import * as Branded from "../schemas/Branded.js";
import * as Entities from "../entities/index.js";

export class SpellNotFound extends Data.TaggedError("SpellNotFound")<{
  readonly unitId: Branded.UnitID;
  readonly spellId: number;
}> {}

export class CastFailed extends Data.TaggedError("CastFailed")<{
  readonly reason: string;
  readonly spell: Entities.Spell.Spell;
  readonly caster?: Entities.Unit.Unit;
}> {}

Error Union Types

Group related errors:

export type RotationError =
  | NoChargesAvailable
  | SpellNotFound
  | SpellOnCooldown
  | UnitNotFound;

export type CombatLogError = QueueEmpty | HandlerError | EventValidationError;

Naming Conventions

  • Error class: {Thing}{Problem} - e.g., SpellNotFound, CastFailed
  • Tag: Same as class name
  • Include relevant context in payload (IDs, entities, messages)

Usage in Effects

import * as Errors from "@wowlab/core/Errors";

// Failing with error
yield *
  Effect.fail(
    new Errors.SpellNotFound({
      unitId,
      spellId,
    }),
  );

// In function signature
const cast = (
  spellId: number,
): Effect.Effect<CastResult, Errors.SpellNotFound | Errors.SpellOnCooldown> =>
  Effect.gen(function* () {
    // ...
  });

Instructions

  1. Identify what can fail
  2. Design payload with useful context
  3. Create error class with TaggedError
  4. Add to union type if applicable
  5. Update function signatures to include error

使用示例

查看来源仓库中的使用示例与配置说明。

查看来源 ↗

来源历史

收录时间
2026-01-20
索引更新时间
2026-01-30
Branch
main

收录与同步日期属于本站记录。源码修改历史请查看来源仓库。

GitHub ↗

chat Comments (0)

chat_bubble_outline

No comments yet. Be the first to share your thoughts!