firstpass_core/error.rs
1//! Error types for the domain contract.
2
3/// Errors produced while constructing or validating domain values.
4#[derive(Debug, thiserror::Error)]
5pub enum Error {
6 /// A [`crate::Score`] was outside the closed unit interval `[0, 1]`.
7 #[error("score {0} out of range [0,1]")]
8 InvalidScore(f64),
9
10 /// A model reference was not of the form `provider/model`.
11 #[error("invalid model reference {0:?} (expected `provider/model`)")]
12 BadModelRef(String),
13
14 /// A duration string was not of the form `<int><unit>` (`s`/`m`/`h`/`d`).
15 #[error("invalid duration {0:?} (expected e.g. `30m`, `2h`)")]
16 BadDuration(String),
17
18 /// Pricing was requested for a model with no entry in the price table.
19 #[error("unknown model {0:?} — add it to the price table")]
20 UnknownModel(String),
21
22 /// The audit hash chain did not verify.
23 #[error("hash chain broken at index {index}: {detail}")]
24 ChainBroken {
25 /// Zero-based position of the first record that failed verification.
26 index: usize,
27 /// Human-readable reason (link mismatch or self-hash mismatch).
28 detail: String,
29 },
30
31 /// TOML config failed to parse.
32 #[error("config parse error: {0}")]
33 Config(#[from] toml::de::Error),
34
35 /// Config parsed but failed a semantic validation check (e.g. an invalid gate definition).
36 #[error("invalid config: {0}")]
37 InvalidConfig(String),
38
39 /// JSON (de)serialization failed — e.g. during canonicalization.
40 #[error("json error: {0}")]
41 Json(#[from] serde_json::Error),
42}
43
44/// Convenience alias for fallible domain operations.
45pub type Result<T> = std::result::Result<T, Error>;