battery-pack-rs/battery-pack/application-errors
Claude Code and agent skill by battery-pack-rs/battery-pack
- community
Checking that the SKILL.md file is still in the repository.
Propagating and formatting errors in Rust applications with anyhow
Install
npx vskill@latest install battery-pack-rs/battery-pack/application-errorsSKILL.md
Application Errors
Propagating and formatting errors in binaries, CLI tools, and services.
Prerequisites: This skill references examples from the error battery pack.```shcargo install cargo-bp # install the battery-pack CLIcargo bp add error # add anyhow + thiserror to your project```
main() Return Type
For CLIs and tools, return anyhow::Result from main() to get automatic error printing:
For services or when you want control over error formatting, handle errors explicitly:
Context Chains with anyhow
When propagating errors, attach context describing what operation was being attempted (not what went wrong, since the source error already says that):
This produces:
.with_context(|| ...) is the lazy variant for expensive format strings. Both also work on Option<T>, converting None into an error.
Formatting for Logs vs Terminals
| Formatter | Output | |
|---|---|---|
{:#} | Single line, colon-separated: outer: middle: root cause | |
{:?} | Multi-line "Caused by:" chain, plus backtrace if captured |
Use {:#} for structured log fields. Use {:?} for terminal output.
For structured logging with tracing, walk the chain explicitly:
Backtrace Configuration
| Variable | Effect | |
|---|---|---|
RUST_BACKTRACE=1 | Capture backtraces on panic | |
RUST_LIB_BACKTRACE=1 | Capture backtraces inside anyhow::Error at creation | |
RUST_LIB_BACKTRACE=0 | Disable anyhow backtraces even when RUST_BACKTRACE=1 |
For production services, set `RUST_BACKTRACE=1 RUST_LIB_BACKTRACE=0`. Backtrace capture can be expensive under contention, and under high error rates the overhead can cause cascading latency spikes.
When to Reach for Custom Types
anyhow is the right default, but define a custom error type when you need to branch on the error programmatically:
This composes with anyhow: library layers use anyhow::Result with .context(), and the outer handler maps into AppError at the boundary. #[from] anyhow::Error acts as a catch-all for unexpected failures.
For errors that cross crate boundaries or need semver stability, see the library-errors skill.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingbattery-packs/error-battery-pack/skills/application-errors/SKILL.md
Popularity
- Repository stars
- 78
- Repository forks
- 12
- 7-day trend score
- 22
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
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/battery-pack-rs/battery-pack/application-errors)