agentleFS
theseus-runtheseus-run/theseus/.agents/skills/effect-errors-schema/SKILL.md

effect-errors-schema

Skill1 starsChanged 6 months agoMITView on GitHub

Use when modeling Effect errors, defects, Cause handling, Schema contracts, Schema.TaggedErrorClass, boundary decoding/encoding, RPC/tool/persistence validation, and typed failure recovery in Theseus.

The file

Show its rules and text

We split this skill into the rules it gives an agent

22 rules. About 0 are common, 8 are distinctive, and 14 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈8

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 14

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill for typed failures, schema contracts, and boundary normalization.

    line 8
  2. Distinctive:

    Use explicit domain errors.

    line 12
  3. Very specific:

    Use Data.TaggedError for plain runtime/domain errors.

    line 18
  4. Very specific:

    Use Schema.TaggedErrorClass when the error must be schema-backed or serialized.

    line 19
  5. Very specific:

    Use Effect.catchTag / Effect.catchTags for known tagged failures.

    line 20
  6. Very specific:

    Use Effect.catch for all typed failures only when deliberately collapsing the union.

    line 21
  7. Very specific:

    Use Effect.catchCause when interrupts or defects must be inspected.

    line 22
  8. Very specific:

    Use Cause.hasInterruptsOnly(cause) to distinguish pure interruption from failure.

    line 23
  9. Very specific:

    Use Effect.catchDefect only for defect conversion at a boundary.

    line 24
  10. Very specific:

    Use Effect.die, thrown invariant errors, or equivalent hard failure for impossible internal states when types failed to prevent them.

    line 25
  11. Very specific:

    Do not use try/catch inside Effect.gen to catch Effect failures.

    line 26
  12. Distinctive:

    Do not throw expected failures.

    line 27
  13. Distinctive:

    Do not recover from unsupported internal variants, impossible state transitions, or violated contracts with defaults, dropped events, or …

    line 28
  14. Very specific:

    Do not erase error unions with any, unknown, or generic wrappers.

    line 29
  15. Distinctive:

    Use Schema at external boundaries: tool inputs/outputs, RPC, persistence serialization, provider payloads, and config.

    line 46
  16. Very specific:

    Use Schema.Struct, Schema.Union, Schema.Literal, and Schema.Literals for wire contracts.

    line 62
  17. Very specific:

    Use Schema.optional(...) for optional fields in this repo.

    line 63
  18. Distinctive:

    Use branded schemas for IDs that cross service/package boundaries.

    line 64
  19. Distinctive:

    Keep schemas near the boundary they protect unless they are shared API contracts.

    line 66
  20. Distinctive:

    Put JSON parse/stringify for protocol, provider, RPC, and persistence data behind schema-backed boundary helpers when practical.

    line 67
  21. Very specific:

    Keep raw Record<string, unknown> at ingress or opaque passthrough boundaries.

    line 68
  22. Very specific:

    Prefer narrow schemas for commands and events.

    line 69

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Effect Errors And Schema

Use this skill for typed failures, schema contracts, and boundary normalization.

Error Model

Use explicit domain errors. Expected failures stay in the Effect error channel. Defects are bugs, thrown exceptions, rejected promise defects, interrupts, or violated invariants.

Recovery is for expected external uncertainty: user input, network, filesystem, subprocesses, model providers, persistence, environment, and other foreign systems. Controlled internal protocol violations are defects.

Rules:

  • Use Data.TaggedError for plain runtime/domain errors.
  • Use Schema.TaggedErrorClass when the error must be schema-backed or serialized.
  • Use Effect.catchTag / Effect.catchTags for known tagged failures.
  • Use Effect.catch for all typed failures only when deliberately collapsing the union.
  • Use Effect.catchCause when interrupts or defects must be inspected.
  • Use Cause.hasInterruptsOnly(cause) to distinguish pure interruption from failure.
  • Use Effect.catchDefect only for defect conversion at a boundary.
  • Use Effect.die, thrown invariant errors, or equivalent hard failure for impossible internal states when types failed to prevent them.
  • Do not use try/catch inside Effect.gen to catch Effect failures; they are not thrown.
  • Do not throw expected failures.
  • Do not recover from unsupported internal variants, impossible state transitions, or violated contracts with defaults, dropped events, or generic fallbacks.
  • Do not erase error unions with any, unknown, or generic wrappers.

Boundary Pattern

At every external boundary, normalize once:

  • raw input -> Schema decode -> typed input
  • foreign exception -> tagged typed failure
  • domain failure -> explicit response or presentation
  • defect -> logged/crashed/interrupted according to boundary policy

Examples of boundaries: tool calls, RPC handlers, SQLite calls, filesystem, subprocesses, model provider calls, WebSocket messages.

Inside the domain, keep typed values and typed failures. Do not repeatedly decode or stringify internal data. At important internal seams, validate or assert invariants and fail loudly when they are violated.

Schema

Use Schema at external boundaries: tool inputs/outputs, RPC, persistence serialization, provider payloads, and config.

import { Schema } from "effect"

export const UserId = Schema.String.pipe(Schema.brand("UserId"))
export type UserId = Schema.Schema.Type<typeof UserId>

export class RpcError extends Schema.TaggedErrorClass<RpcError>()("RpcError", {
  code: Schema.String,
  message: Schema.String,
}) {}

Rules:

  • Use Schema.Struct, Schema.Union, Schema.Literal, and Schema.Literals for wire contracts.
  • Use Schema.optional(...) for optional fields in this repo.
  • Use branded schemas for IDs that cross service/package boundaries.
  • Decode unknown inputs with Schema.decodeUnknownEffect(schema)(raw) when failures should stay typed.
  • Keep schemas near the boundary they protect unless they are shared API contracts.
  • Put JSON parse/stringify for protocol, provider, RPC, and persistence data behind schema-backed boundary helpers when practical. Raw JSON is acceptable for tests, debug output, or truly opaque passthrough data.
  • Keep raw Record<string, unknown> at ingress or opaque passthrough boundaries. Domain code should receive decoded schemas or explicit extension points.
  • Prefer narrow schemas for commands and events. Avoid Schema.Unknown except for explicitly open extension points.

Checks

  • Is the failure expected and recoverable, or is it a defect?
  • Does the boundary serialize or persist this error?
  • Are parse failures kept typed until the boundary handles them?
  • Are _tag values globally safe where pattern matching crosses modules?
  • Is this recovery handling external uncertainty, or is it hiding a broken internal contract?

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.