Error handling

From Esposter/Esposter · View interactive version

Error handling is an AI agent skill from the GitHub repository Esposter/Esposter. Apply when handling errors or logging in components, composables, stores, server routes, tRPC routers, or queue consumer handlers. Esposter's error handling — neverthrow Results, how each is chained and terminated, where a failure is logged or shown, and how errors are thrown and guarded on the serv

How to use this skill

Skill file

Error Handling Conventions

neverthrow for explicit error handling. No silent swallows — every error is propagated, logged, or shown to the user.

Settled — do not re-propose

Deep dives

try / catch and .then are banned

try in any form and .then/.catch/.finally are no-restricted-syntax errors — getResult/getResultAsync and a chain, withFinalizer/withFinalizerAsync for cleanup; the two disable shapes and Promise.try are references/ban-exceptions.md.

Throwing — never `new Error`

Core Utility

import { getResult, getResultAsync, noop, withFinalizer, withFinalizerAsync } from "@esposter/shared";
// getResult: sync fn → Result<T, Error>
// getResultAsync: async fn → ResultAsync<T, Error>
// noop: () => {} — the ok-handler in .match(noop, errorHandler)
// withFinalizer: sync fn + sync finalizer (e.g. restoring globals)
// withFinalizerAsync: async/sync fn + async/sync finalizer — for all async operations

Who alerts a tRPC rejection — `references/alerting.md`

errorLink alerts some rejection codes itself, so a caller that alerts them again stacks two identical toasts on one failure.

Finalizers — `references/finalizers.md`

withFinalizer and withFinalizerAsync run cleanup either way and then unwrap, so no terminal consumer is needed. No await sits between a resource's opening and its finalizer (error-handling/no-unfinalized-resource).

tRPC Backend Guards

Routers never repeat a null check: requireEntity and requireMutation from server/trpc/guards/, and a rejection asserted with the same family's error constructors (references/server-guards.md).

Client Reads/Writes — Don't Hand-Roll the Chain

useQuery / useMutation already carry this chain for client reads/writes — see the trpc skill (references/client-calls.md) before writing your own around a $trpc call.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.