effect-patterns-error-management
БесплатноБез исполняемых скриптовНе проверенEffect-TS patterns for Error Management. Use when working with error management in Effect-TS applications.
от PaulJPhilp★ 807 звёзд на GitHubОб этом скилле
Effect-TS Patterns: Error Management
This skill provides 15 curated Effect-TS patterns for error management. Use this skill when working on tasks related to:
- error management
- Best practices in Effect-TS applications
- Real-world patterns and solutions
🟢 Beginner Patterns
Pattern Match on Option and Either
Rule: Use Option.match() and Either.match() for declarative pattern matching on optional and error-prone values
Good Example:
Basic Option Matching
import { Option } from "effect";
const getUserName = (id: number): Option.Option<string> => {
return id === 1 ? Option.some("Alice") : Option.none();
};
// Using .match() for declarative pattern matching
const displayUser = (id: number): string =>
getUserName(id).pipe(
Option.match({
onNone: () => "Guest User",
onSome: (name) => `Hello, ${name}!`,
})
);
console.log(displayUser(1)); // "Hello, Alice!"
console.log(displayUser(999)); // "Guest User"
Basic Either Matching
import { Either } from "effect";
const validateAge = (age: number): Either.Either<number, string> => {
return age >= 18
? Either.right(age)
: Either.left("Must be 18 or older");
};
// Using .match() for error handling
const processAge = (age: number): string =>
validateAge(age).pipe(
Either.match({
onLeft: (error) => `Validation failed: ${error}`,
onRight: (validAge) => `Age ${validAge} is valid`,
})
);
console.log(processAge(25)); // "Age 25 is valid"
console.log(processAge(15)); // "Validation failed: Must be 18 or older"
Advanced: Nested Matching
When dealing with nested Option and Either, use nested .match() calls:
import { Option, Either } from "effect";
interface UserProfile {
name: string;
age: number;
}
const getUserProfile = (
id: number
): Option.Option<Either.Either<string, UserProfile>> => {
if (id === 0) return Option.none(); // User not found
if (id === 1) return Option.some(Either.left("Profile incomplete"));
return Option.some(Either.right({ name: "Bob", age: 25 }));
};
// Nested matching - first on Option, then on Either
const displayProfile = (id: number): string =>
getUserProfile(id).pipe(
Option.match({
onNone: () => "User not found",
onSome: (result) =>
result.pipe(
Either.match({
onLeft: (error) => `Error: ${error}`,
onRight: (profile) => `${profile.name} (${profile.age})`,
})
),
})
);
console.log(displayProfile(0)); // "User not found"
console.log(displayProfile(1)); // "Error: Profile incomplete"
console.log(displayProfile(2)); // "Bob (25)"
Anti-Pattern:
Avoid manual conditional checks and nested ternaries:
// ❌ ANTI-PATTERN: Imperative checks with isSome/isLeft
const name = getUserName(1);
let result: string;
if (Option.isSome(name)) {
result = `Hello, ${name.value}!`;
} else {
result = "Guest User";
}
// ❌ ANTI-PATTERN: Nested ternaries
const ageResult = validateAge(25);
const message = ageResult.pipe(
Either.match({
onLeft: () => "Invalid",
onRight: (age) => age >= 21 ? "Can drink" : "Cannot drink",
})
);
// ❌ ANTI-PATTERN: Chained if-else instead of match
function processValue(value: Option.Option<number>): string {
if (Option.isSome(value)) {
if (value.value > 0) {
return "Positive";
} else if (value.value < 0) {
return "Negative";
} else {
return "Zero";
}
}
return "No value";
}
Why these are worse:
- Less readable: The intent is hidden in imperative logic
- Error-prone: Easy to forget cases or introduce bugs
- Mutable state: Often requires intermediate variables
- Less composable: Harder to pipe and combine operations
Rationale:
When you need to handle Option or Either values, use the .match() combinator instead of imperative checks. The .match() method provides a declarative, exhaustive way to handle all cases (Some/None for Option, Right/Left for Either) in a single expression.
Use .match() when:
- You need to handle both success and failure cases
- You want type-safe pattern matching
- You prefer declarative over imperative code
- You need to transform values based on their case
The .match() combinator is superior to manual checks (isSome(), isLeft()) because:
- Declarative: Expresses intent clearly - "match on these cases"
- Type-safe: TypeScript ensures all cases are handled
- Exhaustive: You can't accidentally miss a case
- Composable: Works naturally with
.pipe()for chaining operations - Readable: The structure mirrors the data type itself
Without .match(), you'd need imperative conditionals, which are harder to read and easier to get wrong.
Your First Error Handler
Rule: Use catchAll or catchTag to recover from errors and keep your program running.
Good Example:
import { Effect, Data } from "effect"
Установить effect-patterns-error-management в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл effect-patterns-error-management?
Effect-TS patterns for Error Management. Use when working with error management in Effect-TS applications.
Как установить скилл effect-patterns-error-management?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл effect-patterns-error-management запускает скрипты?
Нет, скилл состоит только из инструкций (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