//! Error types for TTS operations use thiserror::Error; /// Errors that can occur during TTS operations #[derive(Debug, Error)] pub enum TtsError { /// Text processing error #[error("Text processing error: {0}")] TextProcessing(String), /// Phonemization error #[error("Phonemization error: {0}")] Phonemization(String), /// Prosody prediction error #[error("Prosody prediction error: {0}")] Prosody(String), /// Invalid configuration #[error("Invalid configuration: {0}")] InvalidConfig(String), /// Invalid input #[error("Invalid input: {0}")] InvalidInput(String), /// Tensor operation error #[error("Tensor error: {0}")] TensorError(String), /// IO error #[error("IO error: {0}")] IoError(#[from] std::io::Error), /// Serialization error #[error("Serialization error: {0}")] SerializationError(#[from] serde_json::Error), /// Unicode error #[error("Unicode error: {0}")] UnicodeError(String), /// Model error #[error("Model error: {0}")] ModelError(String), /// Vocoding error #[error("Vocoding error: {0}")] VocodingError(String), } /// Result type for TTS operations pub type Result = std::result::Result; #[cfg(test)] mod tests { use super::*; #[test] fn error_display() { let err = TtsError::TextProcessing("normalization failed".to_string()); assert_eq!( err.to_string(), "Text processing error: normalization failed" ); } #[test] fn error_from_io() { let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "file not found"); let tts_err: TtsError = io_err.into(); assert!(matches!(tts_err, TtsError::IoError(_))); } #[test] fn error_from_serde() { let json = "{invalid json"; let result: serde_json::Result = serde_json::from_str(json); let json_err = result.unwrap_err(); let tts_err: TtsError = json_err.into(); assert!(matches!(tts_err, TtsError::SerializationError(_))); } }