Skip to main content

lexicon_spec/
error.rs

1use thiserror::Error;
2
3use crate::version::SchemaVersion;
4
5/// Errors that can occur when working with lexicon spec types.
6#[derive(Debug, Error)]
7pub enum SpecError {
8    #[error("incompatible schema version: found {found}, expected compatible with {expected}")]
9    IncompatibleVersion {
10        found: SchemaVersion,
11        expected: SchemaVersion,
12    },
13
14    #[error("validation error: {message}")]
15    Validation { message: String },
16
17    #[error("missing required field: {field}")]
18    MissingField { field: String },
19
20    #[error("duplicate id: {id}")]
21    DuplicateId { id: String },
22
23    #[error("invalid contract id: {id} — must be a non-empty kebab-case slug")]
24    InvalidContractId { id: String },
25
26    #[error("parse error: {0}")]
27    Parse(String),
28
29    #[error("TOML serialization error: {0}")]
30    TomlSerialize(#[from] toml::ser::Error),
31
32    #[error("TOML deserialization error: {0}")]
33    TomlDeserialize(#[from] toml::de::Error),
34
35    #[error("JSON error: {0}")]
36    Json(#[from] serde_json::Error),
37
38    #[error("IO error: {0}")]
39    Io(#[from] std::io::Error),
40}
41
42/// Result type alias for spec operations.
43pub type SpecResult<T> = Result<T, SpecError>;