effect-error-handling
БесплатноБез исполняемых скриптовНе проверенUse when Effect error handling patterns including catchAll, catchTag, either, option, and typed errors. Use for handling expected errors in Effect applications.
от TheBushidoCollective★ 202 звезды на GitHubОб этом скилле
Effect Error Handling
Master type-safe error handling in Effect applications. This skill covers expected errors, error recovery, selective error handling, and error transformations using Effect's error management operators.
Expected Errors vs Defects
Effect distinguishes between two types of failures:
- Expected Errors (E channel): Recoverable errors tracked in the type system
- Defects: Unexpected failures (bugs, programming errors)
import { Effect } from "effect"
// Expected error - tracked in type
interface ValidationError {
_tag: "ValidationError"
field: string
message: string
}
const validateEmail = (email: string): Effect.Effect<string, ValidationError, never> => {
if (!email.includes("@")) {
return Effect.fail({
_tag: "ValidationError",
field: "email",
message: "Invalid email format"
})
}
return Effect.succeed(email)
}
// Defect - throws, becomes unexpected failure
const riskyOperation = Effect.sync(() => {
throw new Error("Unexpected error") // This is a defect
})
// Proper way - expected error
const safeOperation = Effect.try({
try: () => {
// Code that might throw
return riskyParse(data)
},
catch: (error) => ({
_tag: "ParseError",
message: String(error)
})
})
Tagged Error Types
Use tagged unions for error types to enable pattern matching:
import { Effect } from "effect"
// Define tagged error types
interface NotFoundError {
_tag: "NotFoundError"
id: string
}
interface UnauthorizedError {
_tag: "UnauthorizedError"
userId: string
}
interface NetworkError {
_tag: "NetworkError"
message: string
}
type AppError = NotFoundError | UnauthorizedError | NetworkError
// Functions returning typed errors
const fetchUser = (id: string): Effect.Effect<User, NotFoundError | NetworkError, never> => {
// Implementation
}
const authenticate = (token: string): Effect.Effect<User, UnauthorizedError | NetworkError, never> => {
// Implementation
}
Catching All Errors
Effect.catchAll - Recover from Any Error
Catches all expected errors and provides fallback:
import { Effect } from "effect"
const program = Effect.gen(function* () {
const user = yield* fetchUser("123")
return user
}).pipe(
Effect.catchAll((error) =>
Effect.succeed({ id: "default", name: "Guest" })
)
)
// Effect<User, never, never> - Error channel is now never
// With error inspection
const programWithLogging = Effect.gen(function* () {
const user = yield* fetchUser("123")
return user
}).pipe(
Effect.catchAll((error) => {
console.error("Error occurred:", error)
return Effect.succeed(defaultUser)
})
)
// Fallback to another effect
const programWithFallback = pipe(
fetchUser("123"),
Effect.catchAll(() => fetchUserFromCache("123"))
)
Selective Error Handling
Effect.catchTag - Handle Specific Error Types
Catches errors by their _tag field:
import { Effect, pipe } from "effect"
const program = pipe(
fetchUser("123"),
Effect.catchTag("NotFoundError", (error) =>
Effect.succeed({ id: error.id, name: "Not Found" })
)
)
// Still can fail with NetworkError
// Handling multiple tags
const program2 = pipe(
authenticatedRequest(),
Effect.catchTag("UnauthorizedError", (error) =>
Effect.fail({ _tag: "LoginRequired" })
),
Effect.catchTag("NetworkError", (error) =>
retryRequest()
)
)
// Using Effect.gen with early return
const program3 = Effect.gen(function* () {
const result = yield* riskyOperation().pipe(
Effect.catchTag("TemporaryError", () =>
Effect.succeed(null)
)
)
return result
})
Effect.catchTags - Handle Multiple Error Types
import { Effect, pipe } from "effect"
const program = pipe(
complexOperation(),
Effect.catchTags({
NotFoundError: (error) =>
Effect.succeed(defaultValue),
UnauthorizedError: (error) =>
Effect.fail({ _tag: "LoginRequired" }),
NetworkError: (error) =>
retryOperation()
})
)
// With different recovery strategies
const programWithStrategies = pipe(
processPayment(amount),
Effect.catchTags({
InsufficientFunds: (error) =>
Effect.fail({ _tag: "PaymentDeclined", reason: "insufficient-funds" }),
NetworkError: () =>
retryPayment(amount),
ValidationError: (error) =>
Effect.fail({ _tag: "InvalidPayment", field: error.field })
})
)
Effect.catchIf - Conditional Error Handling
Catches errors that match a predicate:
import { Effect, pipe } from "effect"
const isRetryable = (error: AppError): boolean => {
return error._tag === "NetworkError" || error._tag === "TimeoutError"
}
const program = pipe(
fetchData(),
Effect.catchIf(isRetryable, (error) =>
retryFetchData()
)
)
// With type narrowing
const program2 = pipe(
operation(),
Effect.catchIf(
(error): error is NetworkError => error._tag === "NetworkError",
(error) => {
// T
Установить effect-error-handling в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
BashReadWriteEditFAQ
Что делает скилл effect-error-handling?
Use when Effect error handling patterns including catchAll, catchTag, either, option, and typed errors. Use for handling expected errors in Effect applications.
Как установить скилл effect-error-handling?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл effect-error-handling запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic