sevensense_audio/application/
error.rs1use std::path::PathBuf;
4use thiserror::Error;
5
6#[derive(Debug, Error)]
8pub enum AudioError {
9 #[error("Failed to read audio file '{path}': {message}")]
11 FileRead {
12 path: PathBuf,
13 message: String,
14 },
15
16 #[error("Unsupported audio format: {format}")]
18 UnsupportedFormat {
19 format: String,
20 },
21
22 #[error("Resampling failed: {0}")]
24 Resampling(String),
25
26 #[error("Segmentation failed: {0}")]
28 Segmentation(String),
29
30 #[error("Spectrogram computation failed: {0}")]
32 Spectrogram(String),
33
34 #[error("Invalid audio data: {0}")]
36 InvalidData(String),
37
38 #[error("I/O error: {0}")]
40 Io(#[from] std::io::Error),
41
42 #[error("Repository error: {0}")]
44 Repository(String),
45
46 #[error("Configuration error: {0}")]
48 Config(String),
49}
50
51impl AudioError {
52 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 pub fn unsupported_format(format: impl Into<String>) -> Self {
62 Self::UnsupportedFormat {
63 format: format.into(),
64 }
65 }
66
67 pub fn resampling(message: impl Into<String>) -> Self {
69 Self::Resampling(message.into())
70 }
71
72 pub fn segmentation(message: impl Into<String>) -> Self {
74 Self::Segmentation(message.into())
75 }
76
77 pub fn spectrogram(message: impl Into<String>) -> Self {
79 Self::Spectrogram(message.into())
80 }
81
82 pub fn invalid_data(message: impl Into<String>) -> Self {
84 Self::InvalidData(message.into())
85 }
86
87 pub fn repository(message: impl Into<String>) -> Self {
89 Self::Repository(message.into())
90 }
91}
92
93pub type AudioResult<T> = Result<T, AudioError>;