m06-error-handling

Identify Rust error handling approaches for Result, Option, or panic scenarios.

Updated Feb 12, 2026
One-click install
npx skills add https://github.com/jmduea/emotiv-cortex-rs --skill m06-error-handling-jmduea
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: m06-error-handling
Source: https://github.com/jmduea/emotiv-cortex-rs/tree/main/.github/skills/m06-error-handling
Command: npx skills add https://github.com/jmduea/emotiv-cortex-rs --skill m06-error-handling-jmduea

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It helps developers choose the right Rust error handling strategy—whether to use Result, Option, or panic—by distinguishing expected failures from bugs and providing guidance on context propagation.

Core Features & Use Cases

  • Decision Framework: Evaluates when to return Result, use Option, or trigger a panic.
  • Tool Guidance: Recommends thiserror for libraries, anyhow for applications, and appropriate use of ?, unwrap, and expect.
  • Context Enrichment: Shows how to add error context with .context() and when to design custom error enums.

Quick Start

Ask the skill to suggest the best Rust error handling approach for a given code snippet.

Frequently Asked Questions about m06-error-handling

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

FAQPage Schema
When should I use Result, Option, or panic for Rust error handling?

Rust error handling uses Result for recoverable expected failures, Option when a value may be absent, and panic for unrecoverable bugs. Choose based on whether the calling code can reasonably recover from the specific failure condition.

How do I choose between thiserror and anyhow for Rust error handling?

Use thiserror to design custom error enums for libraries where callers need to match specific error variants. Use anyhow in applications to propagate errors with dynamic context, providing flexible error handling without rigid type definitions.

What is the best way to add context to Rust errors during propagation?

Add context to Rust errors by using anyhow's `.context()` method during error propagation. This enriches the error chain with descriptive information, allowing you to track exactly where and why an expected failure occurred across function boundaries.

When is it appropriate to use unwrap and expect in Rust?

Use unwrap and expect in Rust when a failure indicates an unrecoverable bug rather than an expected runtime failure. They trigger a panic, making them suitable for invariant guarantees where missing values signify broken logic rather than recoverable errors.

How do I distinguish between expected failures and bugs in Rust?

Distinguish expected failures from bugs in Rust by assessing recoverability. Expected failures like file-not-found should return Result to allow caller recovery, while bugs like indexing out of bounds should panic to immediately halt execution.