rust-error-handling

Implement Rust error propagation using Result, Option, thiserror, and anyhow.

187|20|Updated Nov 20, 2025
One-click install
npx skills add https://github.com/TheBushidoCollective/han --skill rust-error-handling
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-error-handling
Source: https://github.com/TheBushidoCollective/han/tree/main/jutsu/jutsu-rust/skills/rust-error-handling
Command: npx skills add https://github.com/TheBushidoCollective/han --skill rust-error-handling

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill teaches robust error handling in Rust using Result, Option, and popular crates like thiserror and anyhow.

Core Features & Use Cases

  • Result & Option: Propagate and handle errors cleanly.
  • Custom Errors: Define domain errors with clarity.
  • Libraries: Use thiserror and anyhow for ergonomic error types.

Quick Start

Create a small function returning Result and handle errors at the call site.

Frequently Asked Questions about rust-error-handling

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle errors in Rust using Result and Option?

Result and Option are Rust's core error-handling types. Result wraps success or failure values; Option wraps presence or absence. Use the ? operator to propagate errors cleanly through functions, or match to handle both cases explicitly at decision points.

When should I use thiserror vs anyhow for custom errors?

Use thiserror to define structured, domain-specific error types with clear variants—ideal for libraries and applications that need type safety. Use anyhow for rapid error handling and error chains without defining custom types, better for applications where error details matter less than the chain.

How do I define custom error types in Rust?

Define an enum or struct implementing the std::error::Error trait, or use the thiserror crate to derive Error with #[derive(Error)] and annotate variants with #[error(...)] messages. This gives you typed errors that integrate with Result propagation.

Can I use Result with file I/O and parsing in Rust?

Yes. File I/O and parsing operations return Result by default—std::fs functions and parsing methods wrap errors automatically. Chain them with ? to propagate failures, or map and unwrap_or to provide fallbacks and satisfy type requirements.

What's the best way to propagate errors across service boundaries?

Return Result types from functions at service boundaries, use ? to chain operations cleanly, and convert internal errors to public error types before crossing boundaries. thiserror and anyhow both support error conversion via From trait implementations.

Do I need to handle both Result and Option in the same codebase?

Yes. Use Result for operations that can fail with error detail, and Option for values that may or may not exist. Both work together—convert between them as needed using ok(), err(), and match patterns to fit your error-handling strategy.