igmarin/rust-core-skills · Archived

error-handling

Result over panic. thiserror in libs, anyhow in bins. ? propagation, no unwrap on recoverable errors. Trigger: thiserror, anyhow, unwrap, expect, ?, error chain, eyre.

First seen Aug 21, 2026

Installation

$ npx skills add igmarin/rust-core-skills --skill error-handling

Stronger alternatives

This repository is archived — consider an actively maintained alternative.

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Also in this package

Other skills from igmarin/rust-core-skills.

npx skills add igmarin/rust-core-skills

Browse all from igmarin/rust-core-skills

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Not declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Repository health

License LICENSE
Default branch main
Open issues 0
Status Archived

Skill metadata

Parsed from SKILL.md frontmatter.

Version1.0.0
LicenseMIT
More metadata
version
1.0.0
user-invocable
true

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 2,149 B
  • docs SUMMARY.md 189 B

History

  1. First seen on skills.sh
  2. First recorded snapshot · 2 installs

SKILL.md

Error handling

Goal

Recoverable failure is Result. Panics are bugs, not control flow.

Inputs / outputs

  • In: a fallible operation
  • Out: Result<T, E> with a useful E, or a typed panic only for invariants

Reads / writes

  • Read: the fallible fn and its callers
  • Write: none unless a playbook opened the task

Approval

Adding thiserror / anyhow if they are not already in Cargo.toml.

RULES — no exceptions

  1. Library crates: thiserror (or a small handwritten enum) implementing Error + From
  2. Binary / app crates: anyhow (or the lib error) with .context()
  3. ? to propagate; From impls make ? work
  4. No .unwrap() on user/IO/parse paths
  5. .expect("…") only for proven invariants (a bug if it fires)
  6. Messages: lowercase, no trailing punctuation
  7. Preserve source (#[source] / .context())
  8. Document # Errors on public fallible fns

Example

use std::num::NonZeroU16;

// ❌
let n: u16 = s.parse().unwrap();

// ✅ lib
#[derive(Debug, thiserror::Error)]
enum ParsePortError {
    #[error("not a number")]
    Num(#[from] std::num::ParseIntError),
    #[error("port must be non-zero")]
    Zero,
}

fn parse_port(s: &str) -> Result<NonZeroU16, ParsePortError> {
    let n: u16 = s.parse()?;
    NonZeroU16::new(n).ok_or(ParsePortError::Zero)
}

Steps

  1. Classify: recoverable vs invariant
  2. Recoverable → Result + ?
  3. If the crate is a lib, keep E typed; if a bin, anyhow is enough

Validation

No new unwrap/expect on IO/parse. cargo test covers the error variant.

Pitfalls

❌ ✅
unwrap in a lib ?
expect("failed") on a missing file Err + context
Swallow with let _ = return or log once at the edge

Integration

Predecessor: rust-essentials. Successor: none.