huiali/rust-skills/rust-error-advanced
Claude Code and agent skill by huiali/rust-skills
Trust tier 3
- community
Source check pending
Checking that the SKILL.md file is still in the repository.
深入错误处理专家。处理 Result vs Option, thiserror, anyhow, error context, library vs application errors, 错误处理, Result 用法, 什么时候用 panic--- # 深入错误处理 ## 核心问题 **这个失败是预期的还是 bug?** 错误处理策略决定代码的健壮性。
Install
npx vskill@latest install huiali/rust-skills/rust-error-advancedSKILL.md
Result vs Option vs panic
| 类型 | 何时使用 | 示例 | |
|---|---|---|---|
Result<T, E> | 预期会失败的操作 | 文件读取、网络请求 | |
Option<T> | absence 正常 | 查找、可能为空的值 | |
panic! | bug 或不变式违规 | 程序逻辑错误、不可恢复错误 | |
unreachable!() | 理论上不会执行到的代码 | 匹配穷举 |
错误处理决策
thiserror(库代码)
anyhow(应用代码)
错误设计原则
| 场景 | 建议 | |
|---|---|---|
| 库代码 | thiserror,精确的错误类型 | |
| 应用代码 | anyhow,易于传播和添加上下文 | |
| 库依赖库 | 传递第三方错误(#[from]) | |
| 需要错误码 | 枚举变体 | |
| 需要错误链 | context() + with_context() |
常见反模式
| 反模式 | 问题 | 解决 | |
|---|---|---|---|
处处 unwrap() | 库中 panic | 用 ? | |
Box<dyn Error> | 丢失类型信息 | thiserror 变体 | |
| 丢失上下文 | 调试困难 | .context() | |
| 错误变体过多 | 过度设计 | 简化或合并 |
panic 使用场景
错误链
最佳实践
- 库代码:精确的错误类型(thiserror)
- 应用代码:易用性优先(anyhow)
- 传播错误:用
?而非unwrap() - 添加上下文:使用
.context()或with_context() - 保留错误源:用
#[from]保留底层错误 - 区分 panic 场景:bug 用 panic,预期失败用 Result
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/rust-error-advanced/SKILL.md
Popularity
- Repository stars
- 21
- Repository forks
- 4
- 7-day trend score
- 15
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 23 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/huiali/rust-skills/rust-error-advanced)