Skip to main content

model_router/
error.rs

1//! Crate error type.
2
3use crate::routing::TaskClass;
4use thiserror::Error;
5
6/// Errors returned by the routing core.
7///
8/// The core is deliberately small: the only runtime failure it can produce is
9/// a budget rejection from [`crate::CostTracker::record`] — plus, with the
10/// `json` feature enabled, pricing-table JSON load/serialization failures
11/// from `PricingTable::from_json` / `PricingTable::to_json`.
12#[derive(Debug, Clone, PartialEq, Error)]
13pub enum RouterError {
14    /// A spend record was rejected because it would push total tracked cost
15    /// over the configured USD budget. The tracker is left unmodified.
16    #[error(
17        "budget exceeded: ${current:.4} recorded + ${attempted:.4} requested > ${limit:.2} limit"
18    )]
19    BudgetExceeded {
20        /// Total spend already recorded, in USD.
21        current: f64,
22        /// Cost of the rejected record, in USD.
23        attempted: f64,
24        /// The configured budget limit, in USD.
25        limit: f64,
26    },
27    /// No rule and no default model can satisfy a routing request.
28    #[error("no route available for task class `{task}` and no default model configured")]
29    NoRoute {
30        /// The task class that could not be routed.
31        task: TaskClass,
32    },
33    /// A pricing-table JSON payload could not be parsed or serialized
34    /// (feature `json`). The message carries the underlying serde_json
35    /// detail; the payload itself is not retained.
36    #[error("pricing table JSON error: {0}")]
37    Json(String),
38}