m06-error-handling

Guide Rust error handling with thiserror, anyhow, and layered context propagation.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/AlexKVal/rust-skills-for-cursor --skill m06-error-handling-alexkval
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: m06-error-handling
Source: https://github.com/AlexKVal/rust-skills-for-cursor/tree/main/skills/m06-error-handling
Command: npx skills add https://github.com/AlexKVal/rust-skills-for-cursor --skill m06-error-handling-alexkval

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Rust code can panic or fail to propagate errors cleanly, leading to crashes and poor UX; this skill teaches robust error handling patterns and design considerations.

Core Features & Use Cases

  • Layered thinking: Guides through error detection, propagation, and context augmentation.
  • Opinionated design: Suggests when to use Result/Option, anyhow, thiserror, and panic vs return.
  • Domain-aware decisions: Helps structure error handling across library boundaries and applications.

Quick Start

Demonstrate a layered error-handling example in Rust for a sample function using Result, Option, and thiserror.

Frequently Asked Questions about m06-error-handling

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

FAQPage Schema
What is the best way to handle Rust errors across library boundaries?▼

Handling Rust errors across library boundaries requires structured layering: use thiserror for public library APIs and anyhow for application logic to propagate errors with meaningful context.

How do I add context to Rust error propagation?▼

Adding context to Rust error propagation involves a three-layer design: detect errors, propagate them using Result, and augment with context using anyhow to provide meaningful failure information.

When should I use panic versus return Result in Rust?▼

Use panic in Rust for unrecoverable states or contract violations, and return Result for expected, recoverable failures, ensuring domain-aware decisions guide error handling paths.

How do I structure Rust error handling with thiserror and anyhow?▼

Structure Rust error handling by using thiserror to define custom error types at library boundaries and anyhow to manage dynamic application-level errors across a three-layer propagation design.

Does thiserror work with Option in Rust?▼

thiserror works with Result types in Rust, while Option handles missing values; this skill guides domain-aware decisions on when to convert Option to Result for proper error propagation.

Why does my Rust application crash instead of propagating errors?▼

Rust applications crash when code panics instead of returning Result; applying a layered error handling design with context propagation prevents crashes and improves UX.