tauri_plugin_audio_recorder/
error.rs

1use serde::{ser::Serializer, Serialize};
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Debug, thiserror::Error)]
6pub enum Error {
7    #[error(transparent)]
8    Io(#[from] std::io::Error),
9
10    #[error("Recording error: {0}")]
11    Recording(String),
12
13    #[error("Permission denied: microphone access not granted")]
14    PermissionDenied,
15
16    #[error("No recording in progress")]
17    NotRecording,
18
19    #[error("Already recording")]
20    AlreadyRecording,
21
22    #[error("Audio device not found")]
23    DeviceNotFound,
24
25    #[error("Unsupported audio format")]
26    UnsupportedFormat,
27
28    #[error("Invalid path: {0}")]
29    InvalidPath(String),
30
31    #[cfg(mobile)]
32    #[error(transparent)]
33    PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
34}
35
36impl Serialize for Error {
37    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
38    where
39        S: Serializer,
40    {
41        serializer.serialize_str(self.to_string().as_ref())
42    }
43}