tauri_plugin_media_toolkit/
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("File not found: {0}")]
8    FileNotFound(String),
9
10    #[error("Permission denied: {0}")]
11    PermissionDenied(String),
12
13    #[error("Insufficient storage: required {required} bytes, available {available} bytes")]
14    InsufficientStorage { required: u64, available: u64 },
15
16    #[error("Unsupported codec: {0}")]
17    UnsupportedCodec(String),
18
19    #[error("Invalid time range: start {0}ms, end {1}ms, duration {2}ms")]
20    InvalidTimeRange(u64, u64, u64),
21
22    #[error("Unsupported format: {0}")]
23    UnsupportedFormat(String),
24
25    #[error("FFmpeg error: {0}")]
26    FFmpegError(String),
27
28    #[error("Playback error: {0}")]
29    PlaybackError(String),
30
31    #[error("Export failed: {0}")]
32    ExportFailed(String),
33
34    #[error("No audio track found")]
35    NoAudioTrack,
36
37    #[error("No video track found")]
38    NoVideoTrack,
39
40    #[error("No media loaded")]
41    NoMediaLoaded,
42
43    #[error("Operation cancelled")]
44    Cancelled,
45
46    #[error("Not implemented on this platform")]
47    NotImplemented,
48
49    #[error("Invalid path: {0}")]
50    InvalidPath(String),
51
52    #[error(transparent)]
53    Io(#[from] std::io::Error),
54
55    #[cfg(mobile)]
56    #[error(transparent)]
57    PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
58}
59
60impl Serialize for Error {
61    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
62    where
63        S: Serializer,
64    {
65        serializer.serialize_str(self.to_string().as_ref())
66    }
67}