m06-error-handling

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

1|Updated Nov 27, 2025
One-click install
npx skills add https://github.com/flexisuite-org/FlexiSuite_Kernel --skill m06-error-handling-flexisuite-org
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: m06-error-handling
Source: https://github.com/flexisuite-org/FlexiSuite_Kernel/tree/main/.agents/skills/m06-error-handling
Command: npx skills add https://github.com/flexisuite-org/FlexiSuite_Kernel --skill m06-error-handling-flexisuite-org

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides a comprehensive guide to understanding and implementing robust error handling in Rust, ensuring applications are resilient and maintainable.

Core Features & Use Cases

  • Error Propagation: Learn how to effectively use the ? operator and Result types.
  • Error Types: Differentiate between Result, Option, panic!, and custom error types using thiserror and anyhow.
  • Context and Recovery: Understand when to add context to errors and how to design for recoverable failures versus unrecoverable bugs.
  • Use Case: When developing a new Rust service, use this Skill to decide the best error handling strategy for API responses, database interactions, and internal logic to prevent unexpected crashes and provide clear error messages.

Quick Start

Explain the difference between using panic! and returning a Result in Rust.

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 errors in Rust using Result and Option?

Rust error handling distinguishes recoverable failures using Result and Option from unrecoverable bugs using panic!. This guide explains propagation, context addition, and recovery design to ensure applications are resilient and maintainable.

When should I use panic! versus returning a Result type in Rust?

Use panic! for unrecoverable bugs and return a Result for recoverable errors. This guide covers decision-making for error propagation, helping distinguish between situations requiring safe recovery and those indicating logic failures.

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

Choose thiserror for library error design and anyhow for application-level error handling. This guide differentiates custom error types, explaining how to add context and manage propagation across library versus application boundaries.

How do I add context to errors propagated with the ? operator in Rust?

Add context to Rust errors propagated with the ? operator using libraries like anyhow. This guide explains how to enrich error chains, providing clear messages for API responses, database interactions, and internal logic.

What are common Rust error handling anti-patterns I should avoid?

Common Rust error handling anti-patterns include misusing panic! for recoverable errors and ignoring Result values. This guide identifies these pitfalls, guiding robust propagation, context addition, and proper library versus application design.