1use thiserror::Error;
4
5#[derive(Error, Debug, Clone)]
7pub enum TextError {
8 #[error("Invalid input: {0}")]
10 InvalidInput(String),
11
12 #[error("Tokenization error: {0}")]
14 TokenizationError(String),
15
16 #[error("Text processing error: {0}")]
18 ProcessingError(String),
19
20 #[error("Vocabulary error: {0}")]
22 VocabularyError(String),
23
24 #[error("Embedding error: {0}")]
26 EmbeddingError(String),
27
28 #[error("Distance calculation error: {0}")]
30 DistanceError(String),
31
32 #[error("IO error: {0}")]
34 IoError(String),
35
36 #[error("Error: {0}")]
38 Other(String),
39
40 #[error("Model not fitted: {0}")]
42 ModelNotFitted(String),
43
44 #[error("Runtime error: {0}")]
46 RuntimeError(String),
47}
48
49pub type Result<T> = std::result::Result<T, TextError>;
51
52impl From<std::io::Error> for TextError {
54 fn from(err: std::io::Error) -> Self {
55 TextError::IoError(err.to_string())
56 }
57}
58
59impl From<scirs2_core::CoreError> for TextError {
61 fn from(err: scirs2_core::CoreError) -> Self {
62 TextError::RuntimeError(err.to_string())
63 }
64}
65
66#[cfg(feature = "serde-support")]
68impl From<serde_json::Error> for TextError {
69 fn from(err: serde_json::Error) -> Self {
70 TextError::InvalidInput(format!("JSON parsing error: {}", err))
71 }
72}