Skip to main content

speech_prep/
error.rs

1//! Error types for speech-prep.
2
3/// Errors that can occur during audio preprocessing.
4#[derive(Debug, thiserror::Error)]
5pub enum Error {
6    #[error("{0}")]
7    Processing(String),
8
9    #[error("{0}")]
10    InvalidInput(String),
11
12    #[error("{0}")]
13    Configuration(String),
14
15    #[error("{0}")]
16    TemporalOperation(String),
17
18    #[error(transparent)]
19    Io(#[from] std::io::Error),
20
21    #[cfg(any(test, feature = "fixtures"))]
22    #[error(transparent)]
23    Json(#[from] serde_json::Error),
24}
25
26impl Error {
27    pub fn processing(msg: impl Into<String>) -> Self {
28        Self::Processing(msg.into())
29    }
30
31    pub fn invalid_input(msg: impl Into<String>) -> Self {
32        Self::InvalidInput(msg.into())
33    }
34
35    pub fn configuration(msg: impl Into<String>) -> Self {
36        Self::Configuration(msg.into())
37    }
38
39    pub fn temporal_operation(msg: impl Into<String>) -> Self {
40        Self::TemporalOperation(msg.into())
41    }
42
43    pub fn invalid_format(msg: impl Into<String>) -> Self {
44        Self::InvalidInput(msg.into())
45    }
46
47    pub fn empty_input(msg: impl Into<String>) -> Self {
48        Self::InvalidInput(msg.into())
49    }
50}
51
52pub type Result<T> = std::result::Result<T, Error>;