agentleFS
narenaryannarenaryan/agent-skills/skills/rust/rust-error-identity-boundaries/SKILL.md

rust-error-identity-boundaries

Skill0 starsChanged 39 days agoMITView on GitHub

Use when adding Rust error context or wrappers changes recovery behavior, or when reviewing anyhow and thiserror boundaries for preserved types, causes, and operation details.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Treat diagnostic text, concrete error identity, and the source chain as separate contracts.

    line 8
  2. Very specific:

    Use explicit map_err construction when a thiserror wrapper must retain both operation fields and its original source.

    line 16
  3. Distinctive:

    Test direct typed-context downcasts, domain-wrapper traversal, and the broken stringification alternative.

    line 20

≈ “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

Rust Error Identity Boundaries

Treat diagnostic text, concrete error identity, and the source chain as separate contracts. An informative message does not prove that callers can still classify the failure.

Preserve the information needed by callers

  1. Identify the classification contract before changing an error boundary: a domain variant, a typed operation marker, an underlying source kind, or a combination. Do not branch on formatted messages.
  2. Preserve existing errors with ?, anyhow::Error::new, or an explicit domain wrapper.
  3. Attach operation information using anyhow context. Typed context can classify the operation while ordinary text explains it. Additional context preserves anyhow's existing downcasts. Context values require Display + Send + Sync + 'static; a marker need not implement std::error::Error. Use with_context for lazily prepared details.
  4. Select the traversal the contract requires. Inspect a domain error directly, or use chain() and downcast each cause when classification genuinely depends on a lower-level type. Keep operation context as a separate classification condition when necessary.
  5. Use explicit map_err construction when a thiserror wrapper must retain both operation fields and its original source.

Regression evidence

Test direct typed-context downcasts, domain-wrapper traversal, and the broken stringification alternative. Add unrelated and different-kind failures as negative controls. Change human-readable context without changing the classification. Assert retained fields and source kinds independently of display text.

The original fixture uses synthetic errors with no filesystem or network operations. See provenance and validation limits before running it. Its direct dependencies are version-pinned; compilation and runtime are unverified.

Pitfalls

  • Anyhow context downcasts are not arbitrary source-chain searches. Introducing a domain wrapper changes the concrete underlying error; direct downcasts to its source can fail.
  • Stringification destroys original types and causes. Later context cannot reconstruct that information.
  • #[from] implies #[source] but permits only the source field and an optional backtrace, not extra operation fields. #[error(transparent)] forwards Display and source behavior rather than adding a diagnostic layer.

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.