/ratchet-backend:error-handlingfrom ratchet-backend
Use when writing or reviewing code that throws, catches, or matches an error, turns a failure into a response, or reports errors to a tracker such as Sentry, including a review of a diff that does. Covers one defined list of error codes, matching on type or code instead of message, details as attributes on the error, and reporting only errors someone can act on.
Ships in ratchet-backend. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Read every applicable AGENTS.md first. Repository-local policy overrides these defaults.
An error has three readers: the code that catches it, the client that shows it, and the person who is paged for it. Each needs something other than a sentence to parse.
For the log line that records an error, use structured-logging. For where a handler maps an
error to a response, use http-api-design.
not_found in one place and NotFound in another. One list can be
searched, documented for clients, and switched over exhaustively.export const ERROR_CODES = ['order_not_found', 'refund_exceeds_total', 'payments_down'] as const
export type ErrorCode = (typeof ERROR_CODES)[number]
export class AppError extends Error {
constructor(
readonly code: ErrorCode,
readonly status: number,
message: string,
readonly details: Record<string, unknown> = {},
options?: ErrorOptions,
) {
super(message, options)
}
}
Decide what an error is from its class or type, or from its code. Do not search its message.
// Avoid: breaks when the sentence is reworded, translated, or changed by an upgrade.
if (err.message.includes('duplicate key')) return conflict()
// Prefer
if (err instanceof DatabaseError && err.code === '23505') return conflict()
Put what a reader needs about the failure on the error as attributes: the code, the ids involved, the limit and the value that broke it, an upstream status. Keep the message a fixed string.
// Avoid: the ids exist only inside a sentence.
throw new Error(`Refund ${amount} exceeds total for order ${orderId}`)
// Prefer
throw new AppError('refund_exceeds_total', 422, 'Refund exceeds the order total', {
orderId,
amount,
total,
})
A failed telemetry read, such as a log query, an API read, or a metrics query, is never "nothing found": fail or retry. Treat an empty result as "nothing found" only when a control read proves the source covered what you asked about. For example, the same log group holds a line stamped after the window ends, or a get-item returned a definite not-found. Otherwise, fail or retry. A source that lagged, or a query that matched the wrong window, also returns no rows. Code that reacts to "found nothing", such as a self-healing path, a cleanup, or an alert, then never fires, and the failure is reported as a clean result.
Send an error to the error tracker (Sentry or a similar tool) when a person on the team can do something about it: a bug, an unexpected state, a dependency that failed, a 5xx.
catch.const known = err instanceof AppError ? err : null
if (!known || known.status >= 500) {
tracker.captureException(err, { tags: { code: known?.code }, extra: known?.details })
}
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub jongleberry/ratchet-stack --plugin ratchet-backend18 skills in this plugin
/bounded-iterationUse when writing or reviewing a sweep, scheduled job, reconciler, cleanup, dispatcher, backfill, or export - any loop that reads rows. Covers bounding the rows each run reads, sweeps that re-select their own writes, and effects that repeat on every run./event-handlersUse when writing or reviewing code that acts on an event or a state change - a serverless function, a queue consumer, a scheduled task, or a deploy or config hook - and above all one that sleeps or waits before it acts. React to the change instead of waiting a fixed time, de-duplicate by reading current state, and defer work the target is not ready for without losing it./expand-contract-migrationsUse when renaming or dropping a column or table, changing a column type, making a column NOT NULL, renaming an API or event field, splitting or merging tables, or changing a config shape that running code reads. Change a shape in separate deploys so old and new code never disagree./feature-rolloutUse when adding or reviewing a feature flag, a flag's default, rollout or rollback steps, or a change that adds a table, migration, service, or write path. Ship new behavior behind a flag that starts off, treat deploying and enabling as separate steps, and add no table or service that no entry point reaches./glide-mqUse when writing or reviewing a queue producer, worker, dispatcher, scheduler, or flow, choosing which queue or lane a job belongs in, deciding what a job payload carries, or handling a request that waits on a job's result. Design glide-mq queues, jobs, lanes, concurrency, rate limits, and replay safety./http-api-designUse when writing or reviewing an endpoint, route handler, service layer, or an edge or CDN worker in front of an API, choosing identifiers in URLs, storing tokens or one-time codes, or setting cache headers. Shape an HTTP API around resources, thin route handlers, user-facing identifiers, and one owner each for secret storage and cache headers.