use ferrin_spec::error::InvalidArgumentError;
use ferrin_spec::error::JsonParseError;
use ferrin_spec::error::ProviderError;
use ferrin_spec::error::TypeValidationError;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum SchemaError {
#[error(transparent)]
JsonParse(#[from] JsonParseError),
#[error(transparent)]
TypeValidation(#[from] TypeValidationError),
#[error("unsupported json schema keyword {keyword} for {transform}")]
UnsupportedTransform {
transform: &'static str,
keyword: &'static str,
},
#[error("invalid json schema: {message}")]
InvalidSchema {
message: String,
},
}
impl From<SchemaError> for ProviderError {
fn from(error: SchemaError) -> Self {
match error {
SchemaError::JsonParse(error) => Self::from(error),
SchemaError::TypeValidation(error) => Self::from(error),
error @ SchemaError::UnsupportedTransform { .. } => {
Self::from(InvalidArgumentError::new("schema", error.to_string()))
}
SchemaError::InvalidSchema { message } => {
Self::from(InvalidArgumentError::new("schema", message))
}
}
}
}