rust-error-handling | Skill Performance & Reviews | TopRankSkills

TopRank Skills

Home / Skills / tools / rust-error-handling

rust-error-handling

maintained by Dicklesworthstone

star 100 account_tree 22 verified_user MIT License
bolt View GitHub

id: rust-error-handling name: Rust Error Handling description: >- Rust-specific error handling patterns, building on the base error handling skill. Demonstrates the 'extends' composition feature. tags: [error-handling, rust, example] extends: error-handling-base

Rust Error Handling

Rust-specific error handling patterns that extend the base error handling skill.

Rules

  • Use thiserror for defining library error types
  • Use anyhow for application-level error handling
  • Implement std::error::Error trait for custom error types
  • Use the ? operator for ergonomic error propagation
  • Prefer Result<T, E> over panicking for recoverable errors
  • Use unwrap() only in tests or when failure is impossible

Examples

// Define library errors with thiserror
use thiserror::Error;

#[derive(Error, Debug)]
pub enum ConfigError {
    #[error("failed to read config file: {0}")]
    Io(#[from] std::io::Error),

    #[error("invalid config format: {0}")]
    Parse(#[from] toml::de::Error),

    #[error("missing required field: {field}")]
    MissingField { field: String },
}
// Application-level error handling with anyhow
use anyhow::{Context, Result};

fn load_config(path: &str) -> Result<Config> {
    let content = std::fs::read_to_string(path)
        .with_context(|| format!("failed to read config from {}", path))?;

    let config: Config = toml::from_str(&content)
        .context("failed to parse config TOML")?;

    Ok(config)
}

Checklist

  • Custom error types use thiserror derive
  • Error context is added with anyhow::Context
  • No unwrap() calls in production code paths
  • Result is used instead of panic! for recoverable errors

chat Comments (0)

chat_bubble_outline

No comments yet. Be the first to share your thoughts!

Skill Details

GitHub Stars 100
GitHub Forks 22
Created Jan 2026
Last Updated 8个月前
tools tools architecture patterns

Related Skills

dagger-design-proposals
chevron_right
nestjs-expert
chevron_right
docker-expert
chevron_right
kafka-architecture
chevron_right
kafka-streams-topology
chevron_right

Build your own?

Join 12,000+ developers contributing to the Claude ecosystem.