personalagentproxy/proxy/writing-result-code
Claude Code and agent skill by personalagentproxy/proxy
- community
Checking that the SKILL.md file is still in the repository.
Write compact ts-results-es / Do-notation code and refactor verbose Result chains. Use when writing or reviewing code that uses `Result`, `Do`, `Ok`, `Err`, `Result.wrap`, or `Result.wrapAsync` from `@proxy/utils` and `ts-results-es`.
Install
npx vskill@latest install personalagentproxy/proxy/writing-result-codeSKILL.md
Writing Result code
The codebase uses ts-results-es with a Do helper from @proxy/utils instead of try/catch. This skill covers the compact patterns to write and the verbose patterns to refactor away.
Background: AGENTS.md describes the rules (no try/catch, errors as Results, $() to unwrap, $(Err(...)) to short-circuit). This skill is about _style_ on top of those rules.
Compact patterns
1. Do block over sequential isErr guards
When several Results compose, use Do with $() instead of stacked isErr branches. The early-return pattern in AGENTS.md applies, but Do collapses every "if isErr → return Err" into one character.
Verbose:
Compact:
2. Extract repeated error-mapper closures
When the same mapErr shape appears more than once in a function, give it a name. Keeps the chain readable and dedupes the literal.
3. unwrapOr(null) for "any failure → null"
When a chain of Results all collapse to the same sentinel (usually null or a default), unwrapOr is shorter than Do. Reach for Do only when errors propagate; reach for unwrapOr when they're discarded.
Verbose:
Compact:
4. andThen / mapErr for sync chains
Do takes a sync body too, but for two steps it is still more ceremony than the chain. Chain with .andThen (Result → Result) and .mapErr (E → E') instead.
For two chained Results:
5. Extract shared Do blocks when callers duplicate them
If two exported functions wrap the same Do block with different inputs, extract the block as a private helper. Caller signatures stay clean; the body lives once.
6. Type-narrow the Err short-circuit
Inside a Do<T, E>, $(Err(...)) works but TS sometimes widens the error type. Annotate the call site to keep the discriminated union narrow:
Refactor checklist
When reviewing or simplifying existing Result code, look for:
- [ ] Repeated `if (x.isErr()) return Err({...})` in one function → collapse with
Do+mapErr. - [ ] Repeated error-object literals (e.g.
{kind: 'parse', url, cause: ...}three times) → extract atoXErrclosure. - [ ] Two functions with the same Do body → extract a private helper.
- [ ] `isErr() return null` (or any same-sentinel collapse) →
.unwrapOr(sentinel). - [ ] Two-step sync chains using `Do` → switch to
.andThen/.mapErr. - [ ] Explicit `Result.wrapAsync<T, unknown>(...)` generics → drop them if the callback's return type infers cleanly.
- [ ] Verbose existence checks before `JSON.parse` (
typeof === 'object',Array.isArray, …) → replace with a zod schema (z.record(z.string(), z.unknown()),z.discriminatedUnion, etc.).
When NOT to use Do
Do shines when errors share a single output type. Skip it when:
- Each error maps to a distinct output variant (e.g. an outcome type with
network_error,http_errorandunwritablevariants — Do would force an awkward intermediateEtype, and the explicitisErrbranches read more clearly). - The "error" path is a normal control-flow signal that should be discarded (use
unwrapOrinstead). - There's only one Result to handle. Just check it directly.
Rules of thumb
- Reach for
Doonce you have two or more sequential Results that share an error type. - Reach for
.mapErrto translate errors across boundaries (e.g.FetchError→CliError); name the translator if used more than twice. - Reach for
.andThenfor sync two-step chains. - Reach for
.unwrapOrwhen the function's signature already absorbs failure (T | null,T). - Name the closure when it appears more than once — even a 1-line
(cause) => ({kind: 'parse', url, cause})literal earns a name on its third appearance.
Reference: imports
Do, requirePresent, parseSchema, httpRequest, formatFetchError, and readJsonValidated all export from @proxy/utils. Error mappers (e.g. fetchErrToCli) live next to the error type they produce.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/writing-result-code/SKILL.md
Popularity
- Repository stars
- 108
- Repository forks
- 16
- 7-day trend score
- 0
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/personalagentproxy/proxy/writing-result-code)