rust-error-advanced

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

44|7|Updated Jan 22, 2026
One-click install
npx skills add https://github.com/huiali/rust-skills --skill rust-error-advanced
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-error-advanced
Source: https://github.com/huiali/rust-skills/tree/main/.codex/skills/rust-error-advanced
Command: npx skills add https://github.com/huiali/rust-skills --skill rust-error-advanced

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides expert guidance on advanced Rust error handling strategies, helping developers build robust and maintainable applications by effectively managing expected failures, library vs. application errors, and error context.

Core Features & Use Cases

  • Error Type Selection: Differentiates between Result, Option, and panic! for appropriate use cases.
  • Library vs. Application Errors: Guides the use of thiserror for libraries and anyhow for applications.
  • Error Context and Propagation: Demonstrates how to add context using .context() and propagate errors with ? and #[from].
  • Use Case: You are building a Rust web service and need to handle various potential failures like database connection errors, invalid user input, and external API call failures. This skill will help you structure your error handling to provide clear, actionable error messages to both the end-user and for debugging.

Quick Start

Use the rust-error-advanced skill to understand when to use thiserror versus anyhow for error handling in Rust.

Frequently Asked Questions about rust-error-advanced

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

FAQPage Schema
When should I use thiserror vs anyhow for Rust error handling?

Rust error handling best practices dictate using thiserror for libraries to define custom error types and anyhow for applications to manage dynamic errors. This separation ensures proper error context layering and propagation techniques.

How do I add context and propagate errors in Rust using the ? operator?

Propagate Rust errors using the ? operator combined with #[from] for conversions. Add meaningful context to expected failures using .context() to provide clear, actionable error messages for debugging database or API failures.

What is the difference between Result, Option, and panic in Rust?

Result handles expected failures, Option manages absent values, and panic terminates execution for unrecoverable errors. Selecting the appropriate type prevents common Rust anti-patterns and ensures robust application error handling.

How do I handle database and API errors in a Rust web service?

Structure Rust web service error handling by layering context over database and API failures. Use anyhow to aggregate dynamic errors and propagate them with clear, actionable messages for end-users and debugging.

What are common Rust error handling anti-patterns to avoid?

Common Rust error handling anti-patterns include misusing panic for expected failures and ignoring error context. Avoid these by using Result for recoverable errors and employing thiserror or anyhow for structured propagation.