rust-error

Implement typed error handling in Rust with thiserror and anyhow.

Updated Mar 22, 2026
One-click install
npx skills add https://github.com/cecon123/tg-remote-bot --skill rust-error-cecon123
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-error
Source: https://github.com/cecon123/tg-remote-bot/tree/main/.agents/skills/rust-error
Command: npx skills add https://github.com/cecon123/tg-remote-bot --skill rust-error-cecon123

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Rust projects often struggle with stable error reporting, leaking internals, and noisy APIs. This skill codifies practical strategies to model failures with Result, Option, and typed errors (thiserror) while preserving actionable diagnostics across library and application boundaries.

Core Features & Use Cases

  • Use Result for recoverable failures and Option for absence scenarios, with explicit error contexts.
  • Design library APIs with typed errors (thiserror) and application code with flexible contexts (anyhow), plus clear boundaries and conversions.
  • Provide robust error propagation patterns, context chaining, and test coverage for error paths in IO, parsing, and networking.

Quick Start

Describe a robust error handling strategy in Rust using Result, Option, and typed errors with thiserror/anyhow for production libraries.

Frequently Asked Questions about rust-error

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?

Rust error handling uses Result for recoverable failures and Option for absence scenarios, allowing you to propagate errors explicitly with actionable context rather than relying on exceptions.

When should I use thiserror vs anyhow in Rust libraries and applications?

Use thiserror in Rust libraries to define precise typed errors for clean API boundaries, and use anyhow in application code for flexible context chaining and ergonomic error propagation across IO, parsing, and network calls.

What's the best way to propagate errors across library and application boundaries in Rust?

The best way to propagate Rust errors across boundaries is to map typed library errors into application-level contexts using anyhow, ensuring failure modes remain discoverable and diagnostics stay actionable for operators.

How do I write tests for Rust error handling paths in IO and parsing scenarios?

Testing Rust error paths involves asserting specific Result and Option variants, verifying thiserror typed errors and anyhow context chaining to ensure precise failure coverage for IO, parsing, and networking operations.

Why does my Rust library leak internal error details?

Rust libraries leak internal details when using anyhow at API boundaries instead of thiserror typed errors, which encapsulate failure modes precisely and prevent exposing implementation specifics to downstream consumers.

Do I need thiserror and anyhow to handle panics and recoverable failures in Rust?

You need thiserror and anyhow to manage recoverable Result failures with typed contexts, while panics should be reserved for unrecoverable states, ensuring robust Rust error handling without leaking internals.