Skip to content

feat(edda-ledger): add error context enrichment across ledger, serve, and CLI#381

Merged
fagemx merged 1 commit intomainfrom
feat/377-error-context-enrichment
Mar 27, 2026
Merged

feat(edda-ledger): add error context enrichment across ledger, serve, and CLI#381
fagemx merged 1 commit intomainfrom
feat/377-error-context-enrichment

Conversation

@fagemx
Copy link
Copy Markdown
Owner

@fagemx fagemx commented Mar 27, 2026

Summary

Closes #377

  • Layer 1 (edda-ledger ledger.rs): Added .context() / .with_context() to all 45+ Ledger public methods that delegate to SqliteStore. Each context string includes the method name and key identifying parameters (e.g., Ledger::active_decisions(domain=Some("db"))). This enriches errors for ALL callers (serve, CLI, MCP, bridge).

  • Layer 2 (edda-serve lib.rs): Added .context() to all 33 handler open_ledger() calls with the HTTP route name (e.g., GET /api/decisions). This creates a two-layer error chain: GET /api/decisions > Ledger::active_decisions > sqlite error.

  • Layer 3 (CLI): Added .context() to Ledger::open() calls in cmd_draft.rs (8 functions), cmd_bridge.rs (2 functions), and cmd_pair.rs (4 functions) with command name context.

Changes

File Changes
crates/edda-ledger/src/ledger.rs use anyhow::Context + .context() on 45+ delegation methods
crates/edda-serve/src/lib.rs use anyhow::Context + .context() on 33 handler open_ledger() calls
crates/edda-cli/src/cmd_draft.rs .context() on 8 Ledger::open() calls
crates/edda-cli/src/cmd_bridge.rs use anyhow::Context + .context() on 2 Ledger::open() calls
crates/edda-cli/src/cmd_pair.rs use anyhow::Context + .context() on 4 Ledger::open() calls

Test plan

  • cargo fmt --check passes
  • cargo clippy -p edda-ledger -p edda-serve -p edda -- -D warnings passes with zero warnings
  • cargo test --workspace passes (all 1400+ tests, 0 failures)
  • No behavioral changes -- only error message strings are enriched
  • No API changes -- all return types remain anyhow::Result<T>

🤖 Generated with Claude Code

… and CLI (GH-377)

Add .context() / .with_context() to ~80 bare `?` propagation sites
across three layers for better error diagnostics:

- Layer 1 (ledger.rs): All 45+ Ledger public methods now include
  method name and key parameters in error context
- Layer 2 (serve lib.rs): All 33 handler open_ledger() calls now
  include the HTTP route in error context
- Layer 3 (CLI): cmd_draft, cmd_bridge, cmd_pair Ledger::open() calls
  now include command name in error context

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@fagemx
Copy link
Copy Markdown
Owner Author

fagemx commented Mar 27, 2026

Code Review: PR #381 (Round 1) — LGTM 🎉

All P0 and P1 issues have been resolved.

Summary

This PR adds systematic anyhow::Context enrichment across three layers of the error chain:

  • Layer 1 (edda-ledger ledger.rs): 45+ Ledger public methods now carry method-name context with key parameters (e.g., Ledger::get_event(evt_xxx)). Uses .context() for parameterless methods and .with_context(|| format!(...)) for parameterized ones — consistent throughout.
  • Layer 2 (edda-serve lib.rs): All 33 handler open_ledger() calls tagged with METHOD /api/route context strings, plus 1 Ledger::open() call in post_approval_check.
  • Layer 3 (CLI): cmd_draft.rs (8), cmd_bridge.rs (2), cmd_pair.rs (4) — all Ledger::open() calls enriched with module::function: opening ledger pattern.

Quality Checks

Check Result
cargo fmt --check ✅ Clean
cargo clippy --workspace -- -D warnings ✅ Zero warnings
cargo test --workspace ✅ All 1400+ tests pass
Context string consistency ✅ Layer-appropriate patterns used consistently
No behavioral changes ✅ Only error message enrichment
No new dependencies anyhow already a workspace dep

Verdict: LGTM ✅

No critical or high-priority issues remaining. This PR is ready for merge.


Completed after 1 round(s) of automated review-fix loop

@fagemx fagemx merged commit ed71777 into main Mar 27, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(serve,ledger): add .context() to error propagation in critical paths

1 participant