Skip to content

proper error handling #67

Open

Description

@darinkishore

thiserror out the fucking wazoo bro we gotta have error handling STRUCTURED and on LOCK

Activity

  1. darinkishore commented on Feb 11, 2026

    @darinkishore
    CollaboratorAuthor

    should be retriable, nested, good error messages, cuz there are lots of sharp edges and that sucks for d users and d poor ais

  2. darinkishore commented on Feb 12, 2026

    @darinkishore
    CollaboratorAuthor

    Codebase audit — current error handling state

    Already using thiserror:

    • bamltype: BamlParseError, ConvertError, ParseError (well-structured, 3 enums)
    • dspy-rs/core/errors.rs: PredictError, ParseError, LmError, ConversionError, JsonishError, ErrorClass

    Where anyhow leaks through public API:

    • LM::call() → Result<LMResponse> (anyhow)
    • LM::execute_tool_loop() → Result<ToolLoopResult> (anyhow)
    • Cache trait methods → Result<...> (anyhow)
    • DataLoader methods → Result<Vec<Example>> (anyhow) + a custom DataLoadError for some paths
    • ResponseCache methods → anyhow throughout

    Specific gaps:

    1. LM errors aren't typed — network errors, rate limits (429), auth failures (401), model errors (400), and content policy (403) all come back as anyhow::Error. Callers can't match on error kind for retry logic. Need:

      #[derive(thiserror::Error)]
      pub enum LmCallError {
          #[error("rate limited: retry after {retry_after_ms}ms")]
          RateLimited { retry_after_ms: u64 },
          #[error("auth failed: {0}")]
          AuthFailed(String),
          #[error("model error: {status} {body}")]
          ModelError { status: u16, body: String },
          #[error("network error: {0}")]
          Network(#[from] reqwest::Error),
          #[error("content policy violation")]
          ContentPolicy,
          #[error("image responses not supported")]
          UnsupportedContent,
      }
    2. Tool loop errors are stringly typed — "Max tool iterations reached" and "Tool 'x' not found" are anyhow::anyhow!() strings. Should be enum variants.

    3. Cache errors — foyer errors bubble up as anyhow. Should wrap in a CacheError enum.

    4. DataLoader — has DataLoadError for some paths but falls back to anyhow for others (HF download failures, parquet read errors). Should be consistent.

    5. Optimizer errors — optimizers use anyhow::Result throughout. Long-running optimization that fails on trial 47/100 gives you a generic error with no context about which trial, which predictor, what the LM returned.

    Priority order:

    1. LM call errors (blocks LM layer: per-module LM, config merging, retry/backoff #69 retry/backoff — you can't retry intelligently without typed errors)
    2. Tool loop errors (blocks LM tool loop treats max_tool_iterations=1 as immediate failure #61 fix being clean)
    3. Optimizer errors (blocks production use of optimizers)
    4. Cache/DataLoader errors (nice-to-have)

    Related: #61 (tool loop), #69 (retry/backoff), #75 (Image todo panic)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions