sevensense_audio/application/
error.rs

1//! Error types for the audio application layer.
2
3use std::path::PathBuf;
4use thiserror::Error;
5
6/// Errors that can occur during audio processing.
7#[derive(Debug, Error)]
8pub enum AudioError {
9    /// Failed to read audio file.
10    #[error("Failed to read audio file '{path}': {message}")]
11    FileRead {
12        path: PathBuf,
13        message: String,
14    },
15
16    /// Unsupported audio format.
17    #[error("Unsupported audio format: {format}")]
18    UnsupportedFormat {
19        format: String,
20    },
21
22    /// Resampling error.
23    #[error("Resampling failed: {0}")]
24    Resampling(String),
25
26    /// Segmentation error.
27    #[error("Segmentation failed: {0}")]
28    Segmentation(String),
29
30    /// Spectrogram computation error.
31    #[error("Spectrogram computation failed: {0}")]
32    Spectrogram(String),
33
34    /// Invalid audio data.
35    #[error("Invalid audio data: {0}")]
36    InvalidData(String),
37
38    /// I/O error.
39    #[error("I/O error: {0}")]
40    Io(#[from] std::io::Error),
41
42    /// Repository error.
43    #[error("Repository error: {0}")]
44    Repository(String),
45
46    /// Configuration error.
47    #[error("Configuration error: {0}")]
48    Config(String),
49}
50
51impl AudioError {
52    /// Creates a FileRead error.
53    pub fn file_read(path: impl Into<PathBuf>, message: impl Into<String>) -> Self {
54        Self::FileRead {
55            path: path.into(),
56            message: message.into(),
57        }
58    }
59
60    /// Creates an UnsupportedFormat error.
61    pub fn unsupported_format(format: impl Into<String>) -> Self {
62        Self::UnsupportedFormat {
63            format: format.into(),
64        }
65    }
66
67    /// Creates a Resampling error.
68    pub fn resampling(message: impl Into<String>) -> Self {
69        Self::Resampling(message.into())
70    }
71
72    /// Creates a Segmentation error.
73    pub fn segmentation(message: impl Into<String>) -> Self {
74        Self::Segmentation(message.into())
75    }
76
77    /// Creates a Spectrogram error.
78    pub fn spectrogram(message: impl Into<String>) -> Self {
79        Self::Spectrogram(message.into())
80    }
81
82    /// Creates an InvalidData error.
83    pub fn invalid_data(message: impl Into<String>) -> Self {
84        Self::InvalidData(message.into())
85    }
86
87    /// Creates a Repository error.
88    pub fn repository(message: impl Into<String>) -> Self {
89        Self::Repository(message.into())
90    }
91}
92
93/// Result type for audio operations.
94pub type AudioResult<T> = Result<T, AudioError>;