1use ferrin_spec::error::InvalidArgumentError;
4use ferrin_spec::error::JsonParseError;
5use ferrin_spec::error::ProviderError;
6use ferrin_spec::error::TypeValidationError;
7
8#[derive(Debug, thiserror::Error)]
10#[non_exhaustive]
11pub enum SchemaError {
12 #[error(transparent)]
14 JsonParse(#[from] JsonParseError),
15 #[error(transparent)]
17 TypeValidation(#[from] TypeValidationError),
18 #[error("unsupported json schema keyword {keyword} for {transform}")]
20 UnsupportedTransform {
21 transform: &'static str,
23 keyword: &'static str,
25 },
26 #[error("invalid json schema: {message}")]
28 InvalidSchema {
29 message: String,
31 },
32}
33
34impl From<SchemaError> for ProviderError {
35 fn from(error: SchemaError) -> Self {
36 match error {
37 SchemaError::JsonParse(error) => Self::from(error),
38 SchemaError::TypeValidation(error) => Self::from(error),
39 error @ SchemaError::UnsupportedTransform { .. } => {
40 Self::from(InvalidArgumentError::new("schema", error.to_string()))
41 }
42 SchemaError::InvalidSchema { message } => {
43 Self::from(InvalidArgumentError::new("schema", message))
44 }
45 }
46 }
47}