Skip to main content

any_tts/
error.rs

1//! Error types for any-tts.
2
3use thiserror::Error;
4
5/// Primary error type for all TTS operations.
6#[derive(Error, Debug)]
7pub enum TtsError {
8    /// The requested model type is not compiled in or not supported.
9    #[error("Unsupported model: {0}")]
10    UnsupportedModel(String),
11
12    /// Failed to load model weights from disk.
13    #[error("Failed to load model weights: {0}")]
14    WeightLoadError(String),
15
16    /// Failed to parse model configuration.
17    #[error("Configuration error: {0}")]
18    ConfigError(String),
19
20    /// Error during tensor computation (candle).
21    #[error("Compute error: {0}")]
22    ComputeError(#[from] candle_core::Error),
23
24    /// Error during text tokenization.
25    #[error("Tokenizer error: {0}")]
26    TokenizerError(String),
27
28    /// The requested voice/speaker is not available.
29    #[error("Unknown voice: {0}")]
30    UnknownVoice(String),
31
32    /// The requested language is not supported.
33    #[error("Unsupported language: {0}")]
34    UnsupportedLanguage(String),
35
36    /// I/O error (file access, download, etc.).
37    #[error("I/O error: {0}")]
38    IoError(#[from] std::io::Error),
39
40    /// JSON parsing error.
41    #[error("JSON error: {0}")]
42    JsonError(#[from] serde_json::Error),
43
44    /// Model path was not provided and download is not available.
45    #[error("Model path not specified and download feature is not enabled")]
46    ModelPathMissing,
47
48    /// A required model file was not provided and could not be resolved.
49    #[error("Required file missing: {0}")]
50    FileMissing(String),
51
52    /// Generic error for model-specific issues.
53    #[error("Model error: {0}")]
54    ModelError(String),
55
56    /// Error from an external runtime, process, or HTTP service.
57    #[error("Runtime error: {0}")]
58    RuntimeError(String),
59
60    /// Error during audio encoding (WAV, MP3, etc.).
61    #[error("Audio encoding error: {0}")]
62    AudioError(String),
63}
64
65/// Convenience type alias for Results with [`TtsError`].
66pub type TtsResult<T> = Result<T, TtsError>;