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    #[error(transparent)]
22    Json(#[from] serde_json::Error),
23}
24
25impl Error {
26    pub fn processing(msg: impl Into<String>) -> Self {
27        Self::Processing(msg.into())
28    }
29
30    pub fn invalid_input(msg: impl Into<String>) -> Self {
31        Self::InvalidInput(msg.into())
32    }
33
34    pub fn configuration(msg: impl Into<String>) -> Self {
35        Self::Configuration(msg.into())
36    }
37
38    pub fn temporal_operation(msg: impl Into<String>) -> Self {
39        Self::TemporalOperation(msg.into())
40    }
41
42    pub fn invalid_format(msg: impl Into<String>) -> Self {
43        Self::InvalidInput(msg.into())
44    }
45
46    pub fn empty_input(msg: impl Into<String>) -> Self {
47        Self::InvalidInput(msg.into())
48    }
49}
50
51pub type Result<T> = std::result::Result<T, Error>;