result-not-throw
I return Result<T, E extends Error> from business logic — never throw.
Skill by mateonunez
Chalk Labs
Need help deploying result-not-throw?
Chalk Labs sets up agents like this inside real teams: connected to your tools, tested on your data, with a human in the loop where it matters.
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/mateonunez-result-not-throw
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: writing
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/result-not-throw
What's inside
- Skill name
result-not-throw- Description
- I return Result<T, E extends Error> from business logic — never throw. Errors are typed Error subclasses with a code field (AItError pattern). Throws are reserved for boundary code (Fastify handlers, CLI entry, framework adapters). Use when writing TypeScript service/domain functions, when reviewing code that throws inside happy paths, when the codebase already exposes ok()/err() helpers, or when user says "Result type", "don't throw", or "no exceptions".
- License
- MIT
- Instructions
- 144 lines in SKILL.md · view on GitHub
Files (1)
- SKILL.md
SKILL.md (first lines)
# Result, not throw
> If it doesn't hold up in production, it doesn't make the cut.
Throwing in business logic hides control flow. Failures become invisible until they propagate to a `try/catch` three layers up — by which point the type system has nothing useful to say and the caller has no idea what failure modes exist.
In my code, business logic returns `Result<T, E>`. Throws are reserved for boundaries (Fastify handlers, CLI entry points, framework adapters) where there's no caller to `ok`/`err` against.
This is the [`ait`](../../personal/ait/SKILL.md) pattern, lifted into a public skill. The canonical implementation lives at [`@ait/core/types/result.ts`](../../personal/ait/references/core-result-type.md).
## When this skill is active
You are writing or editing one of:
- A service-layer method (`*Service`, `*Repository`, `*UseCase`)
- A domain function in `packages/*/src/` that is not a handler
- A pure utility that can fail meaningfully (parsing, validation, IO)
If it's a Fastify handler, a CLI command, top-level `main()`, or a test, this skill **does not apply** — those are boundaries.
## The contract
```typescript
// packages/core/src/types/result.ts
export type Ok<T> = { ok: true; value: T };
export type Err<E extends Error = Error> = { ok: false; error: E };
export type Result<T, E extends Error = Error> = Ok<T> | Err<E>;
export const ok = <T>(value: T): Ok<T> => ({ ok: true, value });
export const err = <E extends Error>(error: E): Err<E> => ({ ok: false, error });
```
`E extends Error` — the error channel carries a real `Error` (or subclass), not a plain object. Stack traces still work, `cause` chaining still works, structured loggers still serialise.
If the codebase already has these helpers, **use them**:
```bash
grep -rE "export (const|function) (ok|err)\b" packages/ src/
```
In `ait` they live at `@ait/core` — same elsewhere.
## Phase 1 — Detect
- [ ] Is this boundary code? If yes, throw is fine. Stop.
- [ ] Does the codebase already export `Result<T, E>`, `ok`, `err`? Use them.
- [ ] Is there a typed `Error` subclass for this domain (e.g. `AItError`)? Use it.
- [ ] What are the failure modes? Pick a `code` string for each — `USER_NOT_FOUND`, `DB_ERROR`, `RATE_LIMIT`, `VALIDATION_ERROR`.
## Phase 2 — Type the errors
Errors are `Error` subclasses with a `code` field. Not plain objects, not discriminated unions of primitives. The `Error` base means stack traces, `cause` chaining, and serialisers all keep working; the `code` field gives you the discriminator the caller switches on.
```typescript
// packages/core/src/errors/ait-error.ts
export class AItError extends Error {
readonly code: string;
readonly meta?: Record<string, unknown>;
constructor(
code: string,
message: string,
meta?: Record<string, unknown>,
cause?: unknown,
) {
super(message, { cause });
this.code = code;
this.meta = meta;
this.name = 'AItError';
}
}
```
Common codes I reuse: `USER_NOT_FOUND`, `DB_ERROR`, `AUTH_ERROR`, `CONNECTOR_ERROR`, `RATE_LIMIT`, `VALIDATION_ERROR`, `EMBEDDING_ERROR`, `RETRIEVAL_ERROR`. Pick from the existing catalogue before inventing one.
```typescript
async function fetchUserData(userId: string): Promise<Result<UserData, AItError>> {
try {
const user = await db.users.findById(userId);
if (!user) return err(new AItError('USER_NOT_FOUND', `User ${userId} not found`));
return ok(user);
} catch (e) {
return err(new AItError('DB_ERROR', 'Failed to fetch user', { userId }, e));
}
}
```
The outer `try/catch` here is at the IO seam — that's the right place to convert thrown DB errors into `Result`. Inside business logic, no try/catch.
## Phase 3 — Chain results, propagate early
```typescript
async function processUser(userId: string): Promise<Result<ProcessedData, AItError>> {
const userResult = await fetchUserData(userId);
if (!userResult.ok) return userResult; // propagate
const configResult = await getConnectorConfig(userResult.value.configId);
if (!configResult.ok) return configResult; // propagate
return ok(transform(userResult.value, configResult.value));
}
```
No `if/else` ladders, no nested try/catch — early-return on error, narrow on `ok`.
## Phase 4 — Consume at the boundary
```typescript
// gateway/src/routes/users.ts
fastify.get('/users/:id', async (request, reply) => {
const r = await fetchUserData(request.params.id);
if (!r.ok) {
switch (r.error.code) {
case 'USER_NOT_FOUND': return reply.code(404).send({ error: r.error.code });
case 'DB_ERROR': return reply.code(503).send({ error: r.error.code });
default: return reply.code(500).send({ error: r.error.code });
}
}
return reply.send(r.value);From mateonunez/skills, MIT.
More from mateonunez/skills
- 0.536score
entity-normalization
mateonunez
When data crosses a system boundary into my code, I normalise it into a typed entity with a __type discriminator and a fixed common shape.
SkillCFreshness: C★ 8Claude Code +9 - 0.536score
vertical-slices
mateonunez
I organise code by feature, not by layer.
SkillCFreshness: C★ 8Claude Code +9 - 0.536score
code-review
mateonunez
Review a diff or PR against my conventions — Result not throw, vertical slices, AItError codes, node:test, Biome, entity normalisation, a11y.
SkillCFreshness: C★ 8Claude Code +9 - 0.536score
single-tool-per-job
mateonunez
Biome is enough.
SkillCFreshness: C★ 8Claude Code +9 - 0.536score
production-observability
mateonunez
Include error telemetry, request context, and queue visibility in production code.
SkillCFreshness: C★ 8Claude Code +9 - 0.536score
prototyping
mateonunez
Build a throwaway prototype to flush out a design before committing.
SkillCFreshness: C★ 8Claude Code +9 - 0.536score
setup-mateonunez-skills
mateonunez
Scaffold the per-repo conventions my other engineering skills assume — pnpm + corepack, Biome (1.9 legacy or 2.x new), node:test posture, CONTEXT.md, docs/adr/.
SkillCFreshness: C★ 8Claude Code +9 - 0.536score
node-native-tests
mateonunez
I use node:test + borp + c8, not Jest or Vitest.
SkillCFreshness: C★ 8Claude Code +9 - 0.536score
fastify-plugin-shape
mateonunez
How I write Fastify plugins — fastify-plugin wrapper, idempotency guard, decorator pattern, withX() helper for TS narrowing, module augmentation.
SkillCFreshness: C★ 8Claude Code +9 - 0.535score
fastify-orama
mateonunez
Knowledge pack for fastify-orama — a Fastify plugin that integrates Orama full-text search with persistence support.
SkillCFreshness: C★ 8Claude Code +9 - 0.531score
grill-me-mateo
mateonunez
Grill me on a plan or change before I write code, but with my canonical four questions baked in — package boundary, error code, vertical slice, ADR.
SkillCFreshness: C★ 8Claude Code +9 - 0.511score
triage
mateonunez
Triage issues through a state machine driven by triage roles.
SkillCFreshness: C★ 8Claude Code +9
Signals
- Stars
- 8
- Forks
- 0
- Open issues
- 0
- Last commit (this folder)
- May 7, 2026 (5 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- MIT
- Repository
- github.com/mateonunez/skills
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from mateonunez
- 0.536score
entity-normalization
mateonunez
When data crosses a system boundary into my code, I normalise it into a typed entity with a __type discriminator and a fixed common shape.
SkillCFreshness: C★ 8Claude Code +9 - 0.536score
fastify-plugin-shape
mateonunez
How I write Fastify plugins — fastify-plugin wrapper, idempotency guard, decorator pattern, withX() helper for TS narrowing, module augmentation.
SkillCFreshness: C★ 8Claude Code +9 - 0.536score
code-review
mateonunez
Review a diff or PR against my conventions — Result not throw, vertical slices, AItError codes, node:test, Biome, entity normalisation, a11y.
SkillCFreshness: C★ 8Claude Code +9 - 0.536score
production-observability
mateonunez
Include error telemetry, request context, and queue visibility in production code.
SkillCFreshness: C★ 8Claude Code +9 - 0.536score
prototyping
mateonunez
Build a throwaway prototype to flush out a design before committing.
SkillCFreshness: C★ 8Claude Code +9 - 0.536score
node-native-tests
mateonunez
I use node:test + borp + c8, not Jest or Vitest.
SkillCFreshness: C★ 8Claude Code +9
Done for you
Rather not set it up yourself?
Chalk Labs scopes, builds and runs agents for your team: the task audit, the eval harness, the integrations and the weekly ops report. Fixed scope, priced before we start.
See how we build AI agents →Read the case studies
Chalk Labs is a two-founder AI and growth studio. We build AI agents, CRMs and MVPs for Web3 and AI companies, and have shipped 50+ product and token launches.
- launches shipped
- 50+
- launches shipped
- media placements
- 500+
- media placements
- founders on every account
- 2
- founders on every account
Press we've placed: Forbes · CoinDesk · Decrypt · Cointelegraph · The Block
Rahil Jain, Co-founder, Chalk Labs. Ex-Goldman Sachs engineer. You talk to the person who builds it.
Get result-not-throw running in your business
Tell us what you want to automate. A founder replies within one working day with a plan, not a pitch deck.
Cite this page
result-not-throw skill. Agent Mart. https://agentmart.dev/skills/mateonunez-result-not-throw (last updated 2026-10-24)