Skip to main content

piper_plus/
error.rs

1use piper_plus_g2p::G2pError;
2use thiserror::Error;
3
4#[derive(Error, Debug)]
5pub enum PiperError {
6    #[error("config file not found: {path}")]
7    ConfigNotFound { path: String },
8
9    #[error("invalid config: {reason}")]
10    InvalidConfig { reason: String },
11
12    #[error("model load failed: {0}")]
13    ModelLoad(String),
14
15    #[error("unsupported language: {code}")]
16    UnsupportedLanguage { code: String },
17
18    #[error("unknown phoneme: {phoneme}")]
19    UnknownPhoneme { phoneme: String },
20
21    #[error("inference failed: {0}")]
22    Inference(String),
23
24    #[error("audio output error: {0}")]
25    AudioOutput(#[from] std::io::Error),
26
27    #[error("JSON parse error: {0}")]
28    JsonParse(#[from] serde_json::Error),
29
30    #[error("WAV write error: {0}")]
31    WavWrite(String),
32
33    #[error("phonemization error: {0}")]
34    Phonemize(String),
35
36    #[error("dictionary load error: {path}")]
37    DictionaryLoad { path: String },
38
39    #[error("jpreprocess initialization error: {0}")]
40    JPreprocessInit(String),
41
42    #[error("label parse error: {0}")]
43    LabelParse(String),
44
45    #[error("phoneme ID not found: {phoneme}")]
46    PhonemeIdNotFound { phoneme: String },
47
48    // --- Phase 4 error variants ---
49    #[error("streaming error: {0}")]
50    Streaming(String),
51
52    #[error("playback error: {0}")]
53    Playback(String),
54
55    #[error("timing error: {0}")]
56    Timing(String),
57
58    #[error("download error: {0}")]
59    Download(String),
60
61    #[error("resampling error: {0}")]
62    Resample(String),
63
64    #[error("device error: {0}")]
65    Device(String),
66
67    #[error("batch processing error: {0}")]
68    Batch(String),
69
70    #[error("WASM error: {0}")]
71    Wasm(String),
72}
73
74impl From<G2pError> for PiperError {
75    fn from(e: G2pError) -> Self {
76        match e {
77            G2pError::UnsupportedLanguage { code } => PiperError::UnsupportedLanguage { code },
78            G2pError::UnknownPhoneme { phoneme } => PiperError::UnknownPhoneme { phoneme },
79            G2pError::Phonemize(msg) => PiperError::Phonemize(msg),
80            G2pError::DictionaryLoad { path } => PiperError::DictionaryLoad { path },
81            G2pError::PhonemeIdNotFound { phoneme } => PiperError::PhonemeIdNotFound { phoneme },
82            G2pError::LabelParse(msg) => PiperError::LabelParse(msg),
83            G2pError::JPreprocessInit(msg) => PiperError::JPreprocessInit(msg),
84        }
85    }
86}