m06-error-handling

Guide Rust error handling with Result, Option, panic, thiserror, and anyhow.

1|Updated May 29, 2026
One-click install
npx skills add https://github.com/simorgh3196/tsuzulint --skill m06-error-handling
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: m06-error-handling
Source: https://github.com/simorgh3196/tsuzulint/tree/main/.agents/skills/m06-error-handling
Command: npx skills add https://github.com/simorgh3196/tsuzulint --skill m06-error-handling

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides structured guidance for designing robust error handling in Rust, covering how to choose between Result, Option, and panics, how to define error types, and how to propagate and contextualize errors.

Core Features & Use Cases

  • Understand error-handling strategies across library and application boundaries.
  • Learn to design error types with thiserror and to add context with anyhow or std::error::Error.
  • Apply patterns for error propagation, source wrapping, and user-facing messages in real-world Rust projects.

Quick Start

Refactor a failing function to use typed errors, add context, and implement a clear error path following the guidelines described in this Skill.

Frequently Asked Questions about m06-error-handling

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

FAQPage Schema
What's the best way to structure Rust error handling across library and application boundaries?

Choose Result for expected recoverable failures, Option for absent values, and panic only for unrecoverable contract violations. Design error types with thiserror to propagate typed errors across library boundaries, and use anyhow to add application-level context for user-facing messages.

How do I choose between thiserror and anyhow when designing Rust error types?

Use thiserror to define typed error enums for library APIs, and use anyhow to handle dynamic application errors with added context. This separation keeps library boundaries explicit while simplifying application-level error propagation and user-facing surface messages.

How do I add context to Rust errors during propagation?

Add context to Rust errors by wrapping the underlying std::error::Error source during propagation. Use anyhow's context methods to attach meaningful application-level messages, ensuring the user-facing output clearly explains the failure path across crate boundaries.

When should I use panic instead of Result in Rust?

Use panic in Rust for unrecoverable contract violations or unreachable code, and use Result for expected recoverable failures. Reserve typed errors and Result propagation for expected operational failures to maintain robust library design and application stability.

Does this Skill guide refactoring a failing Rust function to use typed errors?

Yes, the Skill guides refactoring failing Rust functions to use typed errors, add context, and implement clear error paths. It applies patterns for error propagation and source wrapping to real-world Rust projects using thiserror and anyhow.