tauri_plugin_libmpv/
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    #[cfg(mobile)]
10    #[error(transparent)]
11    PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
12    #[error(transparent)]
13    Tauri(#[from] tauri::Error),
14    #[error("Unsupported platform {0}")]
15    UnsupportedPlatform(String),
16    #[error("Not found window with label: '{0}'")]
17    WindowNotFound(String),
18    #[error("Failed to get window handle: {0}")]
19    WindowHandle(#[from] raw_window_handle::HandleError),
20    #[error("FFI error: {0}")]
21    FFI(String),
22    #[error("Failed to create mpv instance")]
23    CreateInstance,
24    #[error("mpv instance not found: {0}")]
25    InstanceNotFound(String),
26    #[error(transparent)]
27    Libloading(#[from] libloading::Error),
28    #[error(transparent)]
29    SerdeJson(#[from] serde_json::Error),
30    #[error(transparent)]
31    NulError(#[from] std::ffi::NulError),
32    #[error("Command failed for window '{window_label}': {message}")]
33    Command {
34        window_label: String,
35        message: String,
36    },
37    #[error("Set Property failed for window '{window_label}': {message}")]
38    SetProperty {
39        window_label: String,
40        message: String,
41    },
42    #[error("Get Property failed for window '{window_label}': {message}")]
43    GetProperty {
44        window_label: String,
45        message: String,
46    },
47    #[error("Invalid value for property '{name}': {message}")]
48    InvalidPropertyValue { name: String, message: String },
49    #[error("Failed to destroy mpv instance: {0}")]
50    Destroy(String),
51}
52
53impl Serialize for Error {
54    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
55    where
56        S: Serializer,
57    {
58        serializer.serialize_str(self.to_string().as_ref())
59    }
60}