typescript-error-modeling-and-boundaries

Designs internal error architecture and boundary translation for strict-mode TypeScript backends.

1|1|Updated Apr 8, 2026
One-click install
npx skills add https://github.com/GonkaGate/opencode-setup --skill typescript-error-modeling-and-boundaries-gonkagate
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-error-modeling-and-boundaries
Source: https://github.com/GonkaGate/opencode-setup/tree/main/.agents/skills/typescript-error-modeling-and-boundaries
Command: npx skills add https://github.com/GonkaGate/opencode-setup --skill typescript-error-modeling-and-boundaries-gonkagate

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? TypeScript backends often end up with inconsistent error handling: message-string matching, swallowed catch blocks, raw infrastructure errors leaking into caller contracts, and confusion over when to throw versus return explicit error values. This Skill provides a disciplined framework for modeling failures and deciding where errors are created, enriched, translated, and shaped across layer boundaries. ## Core Features & Use Cases - Failure-Family Classification: Splits failures into programmer bugs, operational infrastructure failures, expected branching outcomes, and cancellation, then assigns the right signal form (exception, explicit error value, or nullable return) to each. - Stable Error Identity: Enforces machine-readable identity through code or kind discriminants instead of fragile message matching, with cause-based context preservation and caught-unknown normalization. - Boundary Ownership Mapping: Assigns explicit create, enrich, translate, and shape ownership across infrastructure, domain, and transport layers, including Node delivery boundaries like promise rejections and EventEmitter or stream 'error' events. - Use Case: When refactoring a service where route handlers catch raw database errors and branch on error.message, use this Skill to audit the real translation seams, introduce a stable AppError.code contract at handler boundaries, and eliminate swallow-to-null patterns. ## Quick Start Ask the assistant to review your TypeScript service's error handling and recommend where each failure should throw, return an explicit error value, or be translated into an AppError at the route boundary.

Frequently Asked Questions about typescript-error-modeling-and-boundaries

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
When should I throw exceptions versus return explicit error values in TypeScript?

Throw exceptions for programmer bugs and operational infrastructure failures that should abort the current operation. Return explicit error values when the caller is expected to branch on the outcome as normal control flow, such as validation or not-found results.

How do I create stable error identity in TypeScript instead of matching messages?

Use a stable discriminant field like `code` or `kind` as the machine contract, and treat `message` as human-readable text only. Node documents message as unstable across versions, so branching on it breaks when runtimes change.

When is returning null acceptable instead of an error value?

Nullable returns are acceptable only when absence is the sole expected non-success branch and the caller needs no reason, identity, or context. If multiple failure reasons exist, use an explicit error value instead of hiding them behind null.

Does try/catch handle promise rejections and EventEmitter errors in Node?

No. Outer try/catch does not intercept later promise rejections or EventEmitter and stream 'error' events once control has returned. Each delivery boundary needs its own explicit failure strategy, including handling floating promises and unhandled rejections.

How should I preserve error context when wrapping errors in TypeScript?

Use the standard `cause` option in `new Error(message, { cause })` when adding new operation-specific context. Normalize caught `unknown` values near the boundary, and avoid wrapper layers that only restate "Failed to X" without adding new information.

When should I not use this error-boundary approach?

This Skill does not cover public API error-envelope design, neverthrow Result combinator mechanics, or runtime validation of unknown data. Those concerns belong to API contract design, neverthrow flow, and runtime boundary modeling respectively.