use crate::schema::types::SchemaError;
pub struct ErrorFactory;
impl ErrorFactory {
pub fn database_error(operation: &str, error: impl std::fmt::Display) -> SchemaError {
SchemaError::InvalidData(format!("Database {} failed: {}", operation, error))
}
pub fn serialization_error(context: &str, error: impl std::fmt::Display) -> SchemaError {
SchemaError::InvalidData(format!("Serialization failed for {}: {}", context, error))
}
pub fn deserialization_error(context: &str, error: impl std::fmt::Display) -> SchemaError {
SchemaError::InvalidData(format!("Deserialization failed for {}: {}", context, error))
}
pub fn file_error(operation: &str, path: &str, error: impl std::fmt::Display) -> SchemaError {
SchemaError::InvalidData(format!(
"File {} failed for '{}': {}",
operation, path, error
))
}
pub fn lock_error(resource: &str) -> SchemaError {
SchemaError::InvalidData(format!("Failed to acquire lock for {}", resource))
}
pub fn tree_error(
operation: &str,
tree_name: &str,
error: impl std::fmt::Display,
) -> SchemaError {
SchemaError::InvalidData(format!(
"Tree {} operation on '{}' failed: {}",
operation, tree_name, error
))
}
pub fn schema_not_found(schema_name: &str) -> SchemaError {
SchemaError::InvalidData(format!("Schema '{}' not found", schema_name))
}
pub fn field_not_found(schema_name: &str, field_name: &str) -> SchemaError {
SchemaError::InvalidData(format!(
"Field '{}' not found in schema '{}'",
field_name, schema_name
))
}
pub fn transform_not_found(transform_id: &str) -> SchemaError {
SchemaError::InvalidData(format!("Transform '{}' not found", transform_id))
}
pub fn permission_denied(context: &str, details: &str) -> SchemaError {
SchemaError::InvalidData(format!("Permission denied for {}: {}", context, details))
}
pub fn validation_error(context: &str, details: &str) -> SchemaError {
SchemaError::InvalidData(format!("Validation failed for {}: {}", context, details))
}
pub fn iterator_error(context: &str) -> SchemaError {
SchemaError::InvalidData(format!("Iterator exhausted: {}", context))
}
pub fn json_error(operation: &str, error: impl std::fmt::Display) -> SchemaError {
SchemaError::InvalidData(format!("JSON {} failed: {}", operation, error))
}
pub fn conversion_error(from_type: &str, to_type: &str, value: &str) -> SchemaError {
SchemaError::InvalidData(format!(
"Cannot convert {} '{}' to {}",
from_type, value, to_type
))
}
pub fn range_schema_error(schema_name: &str, issue: &str) -> SchemaError {
SchemaError::InvalidData(format!("Range schema '{}' error: {}", schema_name, issue))
}
pub fn message_bus_error(operation: &str, error: impl std::fmt::Display) -> SchemaError {
SchemaError::InvalidData(format!("Message bus {} failed: {}", operation, error))
}
pub fn context_error(context: &str, details: &str) -> SchemaError {
SchemaError::InvalidData(format!("{}: {}", context, details))
}
}