Skip to main content

eval_magic/validation/
error.rs

1//! The error type shared by every validator in this module.
2
3/// A validation failure. Each variant carries the `path` of the artifact under
4/// inspection so messages are actionable.
5///
6/// (The field is named `path` rather than `source` because `thiserror` reserves
7/// a field named `source` for the underlying `std::error::Error` cause.)
8#[derive(Debug, thiserror::Error)]
9pub enum ValidationError {
10    /// `data` failed structural validation against the named schema. `details`
11    /// is one `  <instance-path> <message>` line per failure.
12    #[error("{path}: does not match the {schema} schema:\n{details}")]
13    SchemaMismatch {
14        path: String,
15        schema: String,
16        details: String,
17    },
18
19    /// Two evals share an `id` — a uniqueness constraint JSON Schema (draft-07)
20    /// can't express, so it is checked by hand after structural validation.
21    #[error("{path}: evals[{index}].id duplicate: {id}")]
22    DuplicateId {
23        path: String,
24        index: usize,
25        id: String,
26    },
27
28    /// The data matched the schema but could not be deserialized into the
29    /// requested type — a contract drift between schema and Rust type.
30    #[error("{path}: invalid value after schema validation: {message}")]
31    Deserialize { path: String, message: String },
32}