Whole-workspace rustfmt pass picked up while iterating on Mamba GPU backward work. Verified formatting-only via diff sampling; no logic changed. Co-Authored-By: Claude Sonnet 5 <[email protected]>
85 lines
2.1 KiB
Rust
85 lines
2.1 KiB
Rust
//! 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<T> = std::result::Result<T, TtsError>;
|
|
|
|
#[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::Value> = serde_json::from_str(json);
|
|
let json_err = result.unwrap_err();
|
|
let tts_err: TtsError = json_err.into();
|
|
assert!(matches!(tts_err, TtsError::SerializationError(_)));
|
|
}
|
|
}
|