Skip to content

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

@fagemx

Description

@fagemx

Problem

Error context enrichment is nearly zero across the codebase:

Crate Bare `?` `.context()` Ratio
edda-ledger 613 1 0.16%
edda-cli 546 6 1.1%
edda-serve 215 9 4.2%

When a production error occurs, the error message only contains the lowest-level detail (e.g., "no such column") with no information about which endpoint, decision key, project, or operation triggered it. Debugging is extremely difficult.

Scope

Prioritize adding .context() in:

  1. edda-serve handlers — each ? should include the endpoint name and key request params
  2. edda-ledger public API — each Ledger::* method should wrap errors with the method name and key args
  3. edda-cli commands — each cmd_*.rs execute function should context-wrap ledger calls

Examples

// Before
let ledger = Ledger::open(&root)?;

// After
let ledger = Ledger::open(&root)
    .context(format!("opening ledger at {}", root.display()))?;
// Before (edda-serve handler)
let decisions = ledger.active_decisions()?;

// After
let decisions = ledger.active_decisions()
    .context("GET /api/decisions: fetching active decisions")?;

Notes

  • anyhow is already a workspace dependency — .context() is available everywhere
  • Start with the most-changed files (serve lib.rs, sqlite_store.rs, ledger.rs)
  • This is incremental — doesn't need to be done all at once

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions