Skip to main content

ringkernel_audio_fft/
error.rs

1//! Error types for audio FFT processing.
2
3use thiserror::Error;
4
5/// Result type for audio FFT operations.
6pub type Result<T> = std::result::Result<T, AudioFftError>;
7
8/// Errors that can occur during audio FFT processing.
9#[derive(Error, Debug)]
10pub enum AudioFftError {
11    /// Error reading audio file.
12    #[error("Failed to read audio file: {0}")]
13    FileReadError(String),
14
15    /// Error writing audio file.
16    #[error("Failed to write audio file: {0}")]
17    FileWriteError(String),
18
19    /// Invalid audio format.
20    #[error("Invalid audio format: {0}")]
21    InvalidFormat(String),
22
23    /// FFT processing error.
24    #[error("FFT processing error: {0}")]
25    FftError(String),
26
27    /// Audio device error.
28    #[error("Audio device error: {0}")]
29    DeviceError(String),
30
31    /// K2K messaging error.
32    #[error("K2K messaging error: {0}")]
33    K2KError(String),
34
35    /// Kernel error.
36    #[error("Kernel error: {0}")]
37    KernelError(String),
38
39    /// Configuration error.
40    #[error("Configuration error: {0}")]
41    ConfigError(String),
42
43    /// Buffer underrun/overrun.
44    #[error("Buffer {0}")]
45    BufferError(String),
46
47    /// Processing timeout.
48    #[error("Processing timeout: {0}")]
49    Timeout(String),
50
51    /// RingKernel core error.
52    #[error("RingKernel error: {0}")]
53    RingKernelError(#[from] ringkernel_core::error::RingKernelError),
54
55    /// IO error.
56    #[error("IO error: {0}")]
57    IoError(#[from] std::io::Error),
58}
59
60impl AudioFftError {
61    /// Create a file read error.
62    pub fn file_read(msg: impl Into<String>) -> Self {
63        Self::FileReadError(msg.into())
64    }
65
66    /// Create a file write error.
67    pub fn file_write(msg: impl Into<String>) -> Self {
68        Self::FileWriteError(msg.into())
69    }
70
71    /// Create an invalid format error.
72    pub fn invalid_format(msg: impl Into<String>) -> Self {
73        Self::InvalidFormat(msg.into())
74    }
75
76    /// Create an FFT error.
77    pub fn fft(msg: impl Into<String>) -> Self {
78        Self::FftError(msg.into())
79    }
80
81    /// Create a device error.
82    pub fn device(msg: impl Into<String>) -> Self {
83        Self::DeviceError(msg.into())
84    }
85
86    /// Create a K2K error.
87    pub fn k2k(msg: impl Into<String>) -> Self {
88        Self::K2KError(msg.into())
89    }
90
91    /// Create a kernel error.
92    pub fn kernel(msg: impl Into<String>) -> Self {
93        Self::KernelError(msg.into())
94    }
95
96    /// Create a config error.
97    pub fn config(msg: impl Into<String>) -> Self {
98        Self::ConfigError(msg.into())
99    }
100
101    /// Create a buffer error.
102    pub fn buffer(msg: impl Into<String>) -> Self {
103        Self::BufferError(msg.into())
104    }
105
106    /// Create a timeout error.
107    pub fn timeout(msg: impl Into<String>) -> Self {
108        Self::Timeout(msg.into())
109    }
110}