← ClaudeAtlas

using-result-and-error-codeslisted

Use when handling domain errors, adding exception classes, or working with the LEX_ERR_* error code system in Lexigram
dbtinoy-/lexigram-framework-skills · ★ 1 · AI & Automation · score 72
Install: claude install-skill dbtinoy-/lexigram-framework-skills
# Using Result and Error Codes ## Overview Lexigram uses a two-track error strategy: `Result[T, E]` for expected domain failures, exceptions for unexpected infrastructure failures. Every exception carries a `LEX_ERR_<DOMAIN>_<NNN>` code. ## Two-Track Strategy | Use `Result[T, E]` | Use Exceptions | |---|---| | User not found, validation failed | Database connection lost | | Payment declined, permission denied | Network timeout, OOM | | Business rule violation | Missing API key | | LLM content filter triggered | Serialization bug | ## Result API ```python from lexigram.result import Result, Ok, Err from lexigram.result.utils import as_result, collect, partition result = await service.find_user("123") result.is_ok() / result.is_err() result.unwrap() / result.unwrap_err() # only after is_ok/ is_err check result.unwrap_or(default) / result.unwrap_or_else(fn) # Sync transforms result.map_sync(lambda u: u.email) result.and_then_sync(validate_user) # Async transforms await result.map(load_profile) await result.and_then(create_order) # Exhaustive match msg = result.match( ok=lambda u: f"Found {u.name}", err=lambda e: f"Error: {e}", ) # Utils result.expect("Should have found user") result.to_optional() result.inspect(lambda u: ...) # Chaining helpers (lexigram.result.utils) @as_result(ValueError, KeyError) async def parse(data: str) -> int: ... results = [Ok(1), Err("bad"), Ok(2)] all_ok = collect(results) # Result[list[int], str] oks, errs = partition