use thiserror::Error;
#[derive(Error, Debug, Clone)]
pub enum TextError {
#[error("Invalid input: {0}")]
InvalidInput(String),
#[error("Tokenization error: {0}")]
TokenizationError(String),
#[error("Text processing error: {0}")]
ProcessingError(String),
#[error("Vocabulary error: {0}")]
VocabularyError(String),
#[error("Embedding error: {0}")]
EmbeddingError(String),
#[error("Distance calculation error: {0}")]
DistanceError(String),
#[error("IO error: {0}")]
IoError(String),
#[error("Error: {0}")]
Other(String),
#[error("Model not fitted: {0}")]
ModelNotFitted(String),
#[error("Runtime error: {0}")]
RuntimeError(String),
}
pub type Result<T> = std::result::Result<T, TextError>;
impl From<std::io::Error> for TextError {
fn from(err: std::io::Error) -> Self {
TextError::IoError(err.to_string())
}
}
impl From<scirs2_core::CoreError> for TextError {
fn from(err: scirs2_core::CoreError) -> Self {
TextError::RuntimeError(err.to_string())
}
}
#[cfg(feature = "serde-support")]
impl From<serde_json::Error> for TextError {
fn from(err: serde_json::Error) -> Self {
TextError::InvalidInput(format!("JSON parsing error: {}", err))
}
}