rust-error-observability
Use when adding, changing, debugging, or reviewing Rust service error handling and observability, especially when separating domain errors from HTTP responses, adding thiserror/anyhow, implementing ResponseError or IntoResponse, adding tracing spans, redacting secrets, or diagnosing async failures.
- License 许可
- MIT
- 最近更新
- 2026-06-26
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- rust-error-observability
- license
- MIT
- metadata
- { "tags": "rust,error-handling,observability,tracing,backend", "version": "0.1.0", "category": "Rust", "displayName": "Rust Error Observability" }
- description
- Use when adding, changing, debugging, or reviewing Rust service error handling and observability, especially when separating domain errors from HTTP responses, adding thiserror/anyhow, implementing ResponseError or IntoResponse, adding tracing spans, redacting secrets, or diagnosing async failures.
- compatibility
- Codex, Claude Code, and other Agent Skills-compatible clients.
02 资源文件 4
- 参考文档agents/openai.yaml205 B
- 参考文档references/error-boundaries.md2.1 KB
- 参考文档references/secrets-and-pii.md1.4 KB
- 参考文档references/tracing.md2.0 KB
03 SKILL.md 正文
Rust Error Observability
Use this skill to make Rust service failures understandable to operators while keeping user-facing responses safe. Treat error handling and telemetry as one design surface.
Core Workflow
- Inventory error flows: handler return types, service/repository errors, worker errors, middleware, logs, and tracing setup.
- Classify each error by purpose:
- Domain or validation outcome.
- Recoverable control flow.
- Operator diagnostic.
- User-facing HTTP response.
- Keep domain errors typed. Use
thiserrorfor expected branches that callers should match on. - Add context at infrastructure boundaries. Use
anyhowor opaque application errors when callers should not match every dependency failure. - Map errors to HTTP responses in one place per framework:
ResponseError, AxumIntoResponse, or a small adapter function. - Add structured spans before more log lines. Include stable diagnostic fields, not raw payloads or secrets.
- Ensure errors are logged once. Prefer logging at the outer boundary where request context is available.
- Test both the public response and the diagnostic path when behavior changed.
Error Boundary Rules
- Domain modules return domain errors, not HTTP status codes.
- Repository modules attach query or operation context, but do not log every error.
- Handlers convert domain outcomes into response types and let unexpected failures become a consistent 500.
- Background workers log failed job IDs, attempt counts, and next action.
- Avoid
unwrap,expect, or stringlymap_errin service paths unless the invariant is local and the panic message is useful.
Read references/error-boundaries.md when choosing between thiserror,
anyhow, opaque errors, and framework response adapters.
Tracing Rules
- Instrument request handlers, service methods, outbound clients, database operations, and worker jobs at boundaries.
- Use
#[tracing::instrument(skip(...))]for request bodies, pools, clients, passwords, tokens, and large values. - Attach fields like request ID, user ID, tenant ID, job ID, upstream name, and idempotency key when safe.
- Do not log secrets, cookies, password hashes, bearer tokens, or full PII.
Read references/tracing.md for spans, subscriber setup, and test logging.
Read references/secrets-and-pii.md before touching secret-bearing values.
HTTP Response Pattern
Keep response errors stable and intentional:
pub enum SubscribeError {
Validation(SubscribeValidationError),
Unexpected(anyhow::Error),
}
impl actix_web::ResponseError for SubscribeError {
fn status_code(&self) -> actix_web::http::StatusCode {
match self {
Self::Validation(_) => actix_web::http::StatusCode::BAD_REQUEST,
Self::Unexpected(_) => actix_web::http::StatusCode::INTERNAL_SERVER_ERROR,
}
}
}
The response body should be safe for users. The trace event should carry the diagnostic context operators need.
Reference Files
references/error-boundaries.md: choosing error types and response adapters.references/tracing.md: spans, fields, subscriber setup, and test output.references/secrets-and-pii.md: redaction rules for secrets and sensitive user data.
04 同仓库更多 Skills
android-emulator-qa
Use when validating Android feature flows in an emulator with adb-driven launch, input, UI-tree inspection, screenshots, and logcat capture.
supabase-postgres-best-practices
Postgres performance optimization and best practices from Supabase. Use this skill when writing, reviewing, or optimizing Postgres queries, schema designs, or database configurations.
sentry
Use when the user asks to inspect Sentry issues or events, summarize recent production errors, or pull basic Sentry health data via the Sentry API; perform read-only queries with the bundled script and require `SENTRY_AUTH_TOKEN`.
render-workflows
Sets up, develops, tests, and deploys Render Workflows. Covers first-time scaffolding (via CLI or manual), SDK installation (Python or TypeScript), task patterns (retries, subtasks, fan-out), local development, Dashboard deployment, and troubleshooting. Use when a user wants to set up Render Workflows for the first time, scaffold a workflow service, add or modify workflow tasks, test workflows locally, or deploy workflows to Render.
render-web-services
Configures Render web services—port binding, TLS, health checks, custom domains, auto-deploy, PR previews, persistent disks, and deploy lifecycle. Use when the user needs to set up a web service, fix health check failures, add a custom domain, configure zero-downtime deploys, or troubleshoot port binding issues.
render-static-sites
Deploys and configures static sites on Render's global CDN—build commands, publish paths, SPA routing, redirects, custom headers, and PR previews. Use when the user needs to deploy a static site, set up a React/Vue/Hugo/Gatsby frontend, configure SPA fallback routing, add redirect rules, customize response headers, or choose between a static site and a web service for their frontend. Trigger terms: static site, CDN, SPA, single-page app, React deploy, Vue deploy, Hugo, Gatsby, Docusaurus, Jekyll, staticPublishPath.