Rust Error Advanced
深入错误处理专家。处理 Result vs Option, thiserror, anyhow, error context, library vs application errors, 错误处理, Result 用法, 什么时候用 panic--- # 深入错误处理 ## 核心问题 这个失败是预期的还是 bug? 错误处理策略决定代码的健壮性。
Install
npx skills add huiali/rust-skills --skill rust-error-advancedgit clone --depth 1 https://github.com/huiali/rust-skills.git /tmp/rust-skills
mkdir -p ~/.claude/skills
cp -r /tmp/rust-skills/.codex/skills/rust-error-advanced ~/.claude/skills/rust-error-advancedPersonal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.
From the SKILL.md
## Result vs Option vs panic
| 类型 | 何时使用 | 示例 |
|-----|---------|-----|
| `Result<T, E>` | 预期会失败的操作 | 文件读取、网络请求 |
| `Option<T>` | absence 正常 | 查找、可能为空的值 |
| `panic!` | bug 或不变式违规 | 程序逻辑错误、不可恢复错误 |
| `unreachable!()` | 理论上不会执行到的代码 | 匹配穷举 |
## 错误处理决策
```
失败是预期的吗?
│
├─ 是 → 这是库代码?
│ ├─ 是 → thiserror(类型化错误)
│ └─ 否 → anyhow(易用性)
│
├─ 否,absence 正常?
│ └─ Option<T>
│
└─ 否,bug 或不变式违规
└─ panic!, assert!
```
## thiserror(库代码)
```rust
use thiserror::Error;
#[derive(Error, Debug)]
pub enum MyError {
#[error("validation failed: {0}")]
Validation(String),
#[error("IO error: {source}")]
Io {
#[from]
source: std::io::Error,
},
#[error("not found: {entity}:{id}")]
NotFound {
entity: String,
id: u64,
},
}
// 使用 ? 传播
fn read_config() -> Result<Config, MyError> {
let content = std::fs::read_to_string("config.toml")?;
Ok(toml::from_str(&content)?)
}
```
## anyhow(应用代码)
```rust
use anyhow::{Context, Result, bail};
fn process_user(id: u64) -> Result<User> {
let user = db.find_user(id)
.with_context(|| format!("failed to find user {}", id))?;
if !user.is_active {
bail!("user {} is not active", id);
}
Ok(user)
}
// 组合多个错误源
fn complex_operation() -> Result<()> {
let a = operation_a().context("operation A failed")?;
let b = operation_b().context("operation B failed")?;
Ok(())
}
```
## 错误设计原则
| 场景 | 建议 |Details
- Skill name
rust-error-advanced- Repository
- huiali/rust-skills
- Path
.codex/skills/rust-error-advanced/SKILL.md- License
- MIT
- Repo updated
- 9 February 2026
FAQ
What does the Rust Error Advanced skill do?
深入错误处理专家。处理 Result vs Option, thiserror, anyhow, error context, library vs application errors, 错误处理, Result 用法, 什么时候用 panic--- # 深入错误处理 ## 核心问题 **这个失败是预期的还是 bug?** 错误处理策略决定代码的健壮性。
How do I install the Rust Error Advanced skill?
skills CLI (Claude Code, Cursor, Codex and more): npx skills add huiali/rust-skills --skill rust-error-advanced. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.
Is Rust Error Advanced popular?
It lives in huiali/rust-skills, which has 49 GitHub stars and 7 forks.
Related skills
Rust Actor
49huiali/rust-skills
Actor model expert covering message passing, state isolation, supervision trees, deadlock prevention, fault tolerance, Actix framework, and Erlang-style concurrency patterns.
Rust Anti Pattern
49huiali/rust-skills
Rust anti-patterns and common mistakes expert. Handles code review issues with clone abuse, unwrap in production, String misuse, index loops, and refactoring guidance.
Rust Async
49huiali/rust-skills
Advanced async patterns expert. Handles Stream processing, backpressure control, select/join operations, cancellation, Future trait implementation, and async runtime optimization.
Rust Ffi
49huiali/rust-skills
FFI cross-language interop expert covering C/C++ bindings, bindgen, cbindgen, PyO3, JNI, memory layout, data conversion, and safe FFI patterns.
Rust Error
49huiali/rust-skills
Error handling expert covering Result, Option, panic strategies, custom error types with thiserror/anyhow, error propagation patterns, and context-rich error chains.
Rust GPU
49huiali/rust-skills
GPU 内存与计算专家。处理 CUDA, OpenCL, GPU memory, compute shader, memory coalescing, zero-copy, 显存管理, 异构计算--- # GPU 内存与计算 ## 核心问题 **如何在 Rust 中高效管理 GPU 内存和异构计算?** GPU 计算需要特殊的内存管理策略和同步机制。
Browse the most popular Claude skills, all software development skills, or write your own with the skills generator.