/prometheus-rust-skills:error-handlingfrom prometheus-rust-skills
Canonical Rust error handling for Prometheus AGS projects. Enforces the thiserror/anyhow boundary: thiserror for library crate errors (typed, composable), anyhow for application code (ergonomic, context-rich). Includes #[cold] error path annotation, no unwrap/expect in non-test code, and structured error propagation via the ? operator.
Ships in prometheus-rust-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Library crates (*-core, *-store, *-librarian, etc.) define typed errors with thiserror.
Application crates (*-cli, *-mcp) use anyhow::Result for ergonomic propagation.
// In a library crate (forge-core, pk-store, etc.)
#[derive(thiserror::Error, Debug)]
pub enum StoreError {
#[error("entry not found: {0}")]
NotFound(String),
#[error("serialization failed")]
Serialize(#[from] serde_json::Error),
#[error("I/O error")]
Io(#[from] std::io::Error),
}
// In an application crate (forge-cli, pk-cherry, etc.)
use anyhow::{Context, Result};
fn load_config(path: &Path) -> Result<Config> {
let raw = std::fs::read_to_string(path)
.with_context(|| format!("reading config from {}", path.display()))?;
toml::from_str(&raw).context("parsing config")
}
#[cold]Mark error paths #[cold] and #[inline(never)] to push them out of the hot path
and improve instruction cache behavior. This is especially important in server code
where errors are rare but the hot path runs millions of times.
#[cold]
#[inline(never)]
fn report_store_error(e: &StoreError) {
tracing::error!(error = %e, "store operation failed");
}
// In hot path:
match store.get(id) {
Ok(entry) => process(entry),
Err(e) => { report_store_error(&e); return Err(e.into()); }
}
? Operator and ContextAlways use ? for error propagation. Never use unwrap() or expect() outside of:
#[test] functionsconst evaluation where panic is intentional// SAFETY: commentsWhen using ?, add context to make error messages actionable:
// Bad — "No such file or directory" with no context
let content = std::fs::read_to_string(path)?;
// Good — "reading wiki entry from /path/to/file.md: No such file or directory"
let content = std::fs::read_to_string(path)
.with_context(|| format!("reading wiki entry from {}", path.display()))?;
Use #[from] on thiserror variants for automatic From impl. Use .map_err() when
the conversion is non-trivial or context-dependent.
#[derive(thiserror::Error, Debug)]
pub enum LibrarianError {
// Automatic From<StoreError> via #[from]
#[error("store error")]
Store(#[from] StoreError),
// Manual conversion with context
#[error("LLM API error: {message}")]
LlmApi { message: String },
}
// Manual conversion
async fn compile(raw: RawDoc) -> Result<WikiEntry, LibrarianError> {
let response = call_llm(&raw.content)
.await
.map_err(|e| LibrarianError::LlmApi { message: e.to_string() })?;
// ...
}
Log errors at the boundary where they are handled — not where they originate. Use structured fields so logs are machine-parseable.
match operation().await {
Ok(result) => { /* happy path */ }
Err(e) => {
tracing::error!(
error = %e,
error.kind = std::any::type_name_of_val(&e),
"operation failed"
);
return Err(e.into());
}
}
unwrap() in non-test production code — use ? or matchexpect("message") in non-test production code — add .with_context(|| ...) insteadpanic!() in library crates — return an errorlet _ = risky_operation(); — log or propagateeprintln! for errors — use tracing::error!What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub prometheus-ags/prometheus-skill-system --plugin prometheus-rust-skills13 skills in this plugin
/actor-modelTokio-native actor model pattern for Prometheus AGS projects. Implements actors as tokio tasks communicating via mpsc channels with a typed message enum, enabling safe concurrent state management without shared locks. Used in UAR session management, pk-librarian event broadcasting, and parking-lot scheduler design. Use when a component needs to own state exclusively while serving concurrent callers.
/async-patternsCanonical async Rust patterns for Prometheus AGS projects. Covers tokio task spawning, Arc<RwLock<T>> vs parking_lot::Mutex selection, blocking guard prevention, broadcast channels, graceful shutdown, and structured concurrency. Use whenever writing async code in any Prometheus Fabric crate.
/axum-patternsAxum 0.8 router, middleware, extractor, and state injection patterns for Prometheus AGS projects. Enforces the canonical Axum structure: typed state via Extension/State extractors, Tower middleware composition, structured error types, and Axum-native SSE for MCP servers. Use when building any Axum HTTP service, MCP server, or API gateway in the Prometheus stack.
/karpathy-tokenizerTrain GPT-style BPE tokenizers with rustbpe (Karpathy), export to tiktoken for fast Rust inference, and integrate with agent-tokenizer for prompt-budget enforcement./mcp-serverCanonical Axum MCP server pattern for Prometheus AGS projects. Implements the MCP protocol as JSON-RPC 2.0 over HTTP POST /mcp with optional SSE event stream at GET /events. Covers tool registration, handler dispatch, SSE fan-out via broadcast, and stdio transport for Claude Desktop integration. Use when building any new MCP-enabled service in the Prometheus stack.
/performanceProduction-grade Rust performance primitives for Prometheus AGS projects. Covers jemalloc global allocator, #[cold]/#[inline(never)] for error paths, MaybeUninit for zero-cost initialization, std::mem::take for ownership without clone, Arc placement discipline, parking_lot over std::sync, and SIMD-aware buffer patterns. Apply when writing hot paths, server binaries, or inference-adjacent code.
2 plugins in one repository ship this exact skill · first indexed Nov 27, 2026