{"id":29200119,"url":"https://github.com/josiahbull/anyhow-tracing","last_synced_at":"2026-03-11T01:31:39.229Z","repository":{"id":298085576,"uuid":"998812475","full_name":"JosiahBull/anyhow-tracing","owner":"JosiahBull","description":"An extension of the anyhow crate that provides named fields on errors","archived":false,"fork":false,"pushed_at":"2025-06-10T00:22:06.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-19T16:00:17.702Z","etag":null,"topics":["anyhow","error-handling","logging","macros","rust","tracing"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JosiahBull.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-09T09:39:56.000Z","updated_at":"2025-06-10T00:13:39.000Z","dependencies_parsed_at":"2025-06-09T10:43:54.672Z","dependency_job_id":null,"html_url":"https://github.com/JosiahBull/anyhow-tracing","commit_stats":null,"previous_names":["josiahbull/anyhow-tracing"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/JosiahBull/anyhow-tracing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JosiahBull%2Fanyhow-tracing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JosiahBull%2Fanyhow-tracing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JosiahBull%2Fanyhow-tracing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JosiahBull%2Fanyhow-tracing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JosiahBull","download_url":"https://codeload.github.com/JosiahBull/anyhow-tracing/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JosiahBull%2Fanyhow-tracing/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30366051,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T21:41:54.280Z","status":"ssl_error","status_checked_at":"2026-03-10T21:40:59.357Z","response_time":106,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["anyhow","error-handling","logging","macros","rust","tracing"],"created_at":"2025-07-02T10:06:15.213Z","updated_at":"2026-03-11T01:31:39.195Z","avatar_url":"https://github.com/JosiahBull.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Anyhow-Tracing\n\n[![Crates.io](https://img.shields.io/crates/v/anyhow-tracing.svg)](https://crates.io/crates/anyhow-tracing)\n[![Documentation](https://docs.rs/anyhow-tracing/badge.svg)](https://docs.rs/anyhow-tracing)\n[![Tests](https://github.com/JosiahBull/anyhow-tracing/workflows/Tests/badge.svg)](https://github.com/JosiahBull/anyhow-tracing/actions)\n![License](https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-blue.svg)\n\nAn extension of the `anyhow` crate that provides named fields on an equivalent\nof `anyhow::Error`. Named fields are stored as a `Vec\u003c(\u0026'static str, Box\u003cstr\u003e)\u003e`\nto allow for passing the error object around as an owned instance.\n\n## Features\n\n- **Named Fields**: Add structured key-value fields to errors for better debugging and logging.\n- **Drop-in Replacement**: Compatible macros that work like `anyhow!`, `bail!`, and `ensure!`.\n- **Error Chaining**: Preserves error chains while maintaining named fields, new named fields are added to the error.\n- **Debug and Display Fields**: Support for both `Display` and `Debug` formatting of field values.\n- **Context Extension**: Extends the `Context` trait to work with named fields.\n\n## Quick Start\n\nAdd this to your `Cargo.toml`:\n\n```toml\n[dependencies]\nanyhow-tracing = \"0.1\"\n```\n\n## Basic Usage\n\n```rust\nuse anyhow_tracing::{anyhow, bail, ensure, Context, Error, Result};\n\n// Create errors with named fields\nlet err: Error = anyhow!(\n    user_id = \"user123\",\n    session_id = \"sess456\",\n    \"Authentication failed for user\"\n);\n\n// Access field values\nprintln!(\"User ID: {:?}\", err.get_field(\"user_id\"));\nprintln!(\"Session ID: {:?}\", err.get_field(\"session_id\"));\n\n// Error with debug formatting\nlet data = vec![1, 2, 3];\nlet err: Error = anyhow!(data = ?data, \"Processing failed\");\n\n// Using bail! macro\nfn validate_input(value: i32) -\u003e Result\u003c()\u003e {\n    if value \u003c 0 {\n        bail!(\n            input_value = value.to_string(),\n            constraint = \"non_negative\",\n            \"Invalid input\");\n    }\n    Ok(())\n}\n\n// Using ensure! macro\nfn process_number(value: i32) -\u003e Result\u003ci32\u003e {\n    ensure!(value \u003e= 0, value, \"Number must be non-negative\");\n    ensure!(value \u003c= 100, value, max_allowed = \"100\", \"Number must be at most 100\");\n    Ok(value * 2)\n}\n\n// Error chaining with context\nlet result: Result\u003c()\u003e = Err(anyhow!(component = \"postgresql\", \"Database error\"));\nlet final_result = match result {\n    Ok(v) =\u003e Ok(v),\n    Err(e) =\u003e Err(e.context(\"User service unavailable\"))\n};\n\n// Working with standard library errors\nuse std::fs;\nlet result = fs::read_to_string(\"/nonexistent/file\")\n    .with_field(\"operation\", \"read_config\")\n    .with_field(\"file_type\", \"toml\");\n```\n\n## Context Trait Extensions\n\nThe crate extends the `Context` trait to work with standard library types:\n\n```rust\nuse anyhow_tracing::{Context, Result};\nuse std::fs::File;\n\n// On Result types\nlet result: Result\u003cFile\u003e = File::open(\"/nonexistent/path\")\n    .with_field(\"operation\", \"file_open\");\n\n// On Option types\nlet maybe_value: Option\u003cString\u003e = None;\nlet result: Result\u003cString\u003e = maybe_value\n    .with_field(\"context\", \"parsing\")\n    .context(\"Value was None\");\n```\n\n## Compatibility\n\nThis crate is designed to be a drop-in replacement for `anyhow` with additional functionality. Most `anyhow` code should work with minimal changes, primarily requiring:\n\n1. Import changes: `anyhow` → `anyhow_tracing`\n2. Macro syntax: Use `,` to separate fields and messages - similar to `tracing::event!`.\n3. Method chaining: Be explicit about context operations to avoid trait conflicts\n\n## 📄 License\n\nLicensed under either of\n\n- Apache License, Version 2.0\n   ([LICENSE-APACHE](LICENSE-APACHE) or [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0))\n- MIT license\n   ([LICENSE-MIT](LICENSE-MIT) or [http://opensource.org/licenses/MIT](http://opensource.org/licenses/MIT))\n\nat your option.\n\n## 🤝 Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosiahbull%2Fanyhow-tracing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjosiahbull%2Fanyhow-tracing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosiahbull%2Fanyhow-tracing/lists"}