Rust-specific error handling patterns, building on the base error handling skill. Demonstrates the 'extends' composition feature.
Rust-specific error handling patterns that extend the base error handling skill.
thiserror for defining library error typesanyhow for application-level error handlingstd::error::Error trait for custom error types? operator for ergonomic error propagationResult<T, E> over panicking for recoverable errorsunwrap() only in tests or when failure is impossible// 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)
}
thiserror deriveanyhow::Contextunwrap() calls in production code pathsResult is used instead of panic! for recoverable errorsnpx skills add Dicklesworthstone/Rust Error Handling下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer
Tags:error-handling, rust, example