errors

An error-handling and resilience guide for Bun and TypeScript services. It separates expected operating problems, such as rate limits, from unexpected programming errors, and covers validation, timeouts, retries, and circuit breakers.

In plain words
What is it for?
Use it to structure service errors, validate inputs, handle upstream failures, and add timeout, retry, or circuit-breaker behavior.
Why use it?
It gives different kinds of failures consistent responses and preserves useful error information for diagnosis.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/madappgang/magus/errors
Any agent
npx skills add MadAppGang/magus --skill errors
Clone the repo
git clone --depth 1 https://github.com/MadAppGang/magus

Made for: Claude Code, Codex.

Per session 39 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,142 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00039 $0.02142
Opus 5 $0.00019 $0.01071
Sonnet 5 $0.00008 $0.00428
Haiku 4.5 $0.00004 $0.00214

Measured 2d ago against content hash 5470300fa001, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

errors scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

The scan reads SKILL.md. This mod also ships 7 executable files (assets/errors/app-error.test.ts, assets/errors/app-error.ts, assets/errors/catalog.ts, …), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

await retry(() => withTimeout("charge", 2000, (signal) => fetch(url, { signal })), { attempts: 3 });
plugins/bunjs/skills/errors/SKILL.md · 154 lines

How it starts

The opening of the file, as written. The whole thing — 154 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Errors and resilience

Error handling is where most Node/Bun services rot, and it rots in a specific way: every catch block makes its own decision. One returns null, one logs and continues, one re-throws a new Error(String(e)) that destroys the stack, one 500s on a validation failure. The result is a service that cannot tell you whether it is healthy, because nothing knows what an error means.

This skill installs one distinction and builds everything on it.

The one distinction: operational vs programmer

Operational Programmer
Examples bad email, payment declined, upstream 503, rate limit, 404 undefined is not a function, violated invariant, bad migration
Who was wrong the caller, the network, the world you
Did you anticipate it yes — you wrote the throw no
Correct response answer the caller, log at warn, keep serving log at error with stack, let the process die and restart
Process state after healthy unknown

The last row is the reason this matters. After a programmer error the process holds state nobody reasoned about — a half-applied transaction, a module that threw during init, a connection pool with a poisoned entry. Continuing is not resilience, it is serving unknown-correctness responses. The famous advice "never swallow errors" is really this: never let a programmer error be swallowed into the operational path.

Everything else in this skill follows mechanically. AppError.isOperational() is the classifier; it returns false for anything that is not an AppError, because an unrecognised error is a bug until proven otherwise.

Copy the module in; never retype it

The subtle parts — the cause chain walk that is cycle-safe, the 5xx message replacement, the re-entrancy guard on shutdown, full-jitter backoff — degrade silently when retyped from memory. 53 tests ship with this code and pass (bun test, tsc --noEmit clean, Bun 1.3.10).

SKILL="${CLAUDE_PLUGIN_ROOT:+$CLAUDE_PLUGIN_ROOT/skills/errors}"; SKILL="${SKILL:-PASTE_THE_DIR_THIS_SKILL_MD_WAS_READ_FROM}"  # that var is UNSET in a Bash tool (MEASURED) — so paste it. `:?` would ABORT the block and copy nothing
mkdir -p src; if [ -d "$SKILL/assets" ]; then cp -r "$SKILL/assets/errors" src/errors   # app-error, catalog, handler, resilience + 3 test files
else echo "SKILL is still the placeholder — paste the real dir above and re-run"; fi

Read the full file on GitHub · 154 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 154 lines · 39 tokens per session scan A 5470300fa001

Subscribe to this mod's changes

errors is a skill published in the GitHub repository MadAppGang/magus (9 stars, last pushed 3d ago), licensed MIT. It adds 39 tokens to every session and 2,142 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

systematic-debugging

Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes.

obra/superpowers · 21 tokens

next-cache-components-adoption

Turn on Cache Components in a Next.js app and resolve the blocking routes it surfaces. Use when the user wants to enable, adopt, or migrate to Cache Components, flip the cacheComponents flag, work through a flood of blocking-prerender / instant validation errors, run the cache-components-instant-false codemod, or…

vercel/next.js · 95 tokens

babysit-pr

Babysit a GitHub pull request after creation by continuously polling review comments, CI checks/workflow runs, and mergeability state until the PR is merged/closed or user help is required. Diagnose failures, retry likely flaky failures up to 3 times, auto-fix/push branch-related issues when appropriate, and keep…

openai/codex · 114 tokens

imagegen

Generate or edit raster images when the task benefits from AI-created bitmap visuals such as photos, illustrations, textures, sprites, mockups, or transparent-background cutouts. Use when Codex should create a brand-new image, transform an existing image, or derive visual variants from references, and the output…

openai/codex · 113 tokens

cpu-profile-analysis

Analyze V8/Chrome CPU profiles (.cpuprofile) and DevTools trace files (Trace-.json). Use when: profiling performance, investigating slow functions, comparing code paths, finding bottlenecks, analyzing timeToRequest, understanding call trees from sampling profiler data, analyzing layout/paint/rendering, investigating…

microsoft/vscode · 71 tokens

next-cache-components-optimizer

Drive a Next.js route to instant navigation by setting up an agentic loop, under Cache Components / PPR, on initial load (hard navigation) and client-side navigation (soft navigation). Encode the goal as a failing @next/playwright instant() e2e and work it to green, one verified route at a time; the shipped test then…

vercel/next.js · 170 tokens