tauri_plugin_opener/
error.rs1use std::path::PathBuf;
6
7use serde::{Serialize, Serializer};
8
9#[derive(Debug, thiserror::Error)]
10#[non_exhaustive]
11pub enum Error {
12 #[cfg(mobile)]
13 #[error(transparent)]
14 PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
15 #[error(transparent)]
16 Tauri(#[from] tauri::Error),
17 #[error(transparent)]
18 Io(#[from] std::io::Error),
19 #[error(transparent)]
20 Json(#[from] serde_json::Error),
21 #[error("unknown program {0}")]
22 UnknownProgramName(String),
23 #[error("Not allowed to open path {}{}", .path, .with.as_ref().map(|w| format!(" with {w}")).unwrap_or_default())]
24 ForbiddenPath { path: String, with: Option<String> },
25 #[error("Not allowed to open url {}{}", .url, .with.as_ref().map(|w| format!(" with {w}")).unwrap_or_default())]
26 ForbiddenUrl { url: String, with: Option<String> },
27 #[error("API not supported on the current platform")]
28 UnsupportedPlatform,
29 #[error(transparent)]
30 #[cfg(windows)]
31 Win32Error(#[from] windows::core::Error),
32 #[error("Path doesn't have a parent: {0}")]
33 NoParent(PathBuf),
34 #[cfg(windows)]
36 #[error("Failed to convert path '{0}' to ITEMIDLIST")]
37 FailedToConvertPathToItemIdList(PathBuf),
38 #[error("Failed to convert path to file:// url")]
39 FailedToConvertPathToFileUrl,
40 #[error(transparent)]
41 #[cfg(any(
42 target_os = "linux",
43 target_os = "dragonfly",
44 target_os = "freebsd",
45 target_os = "netbsd",
46 target_os = "openbsd"
47 ))]
48 Zbus(#[from] zbus::Error),
49}
50
51impl Serialize for Error {
52 fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
53 where
54 S: Serializer,
55 {
56 serializer.serialize_str(self.to_string().as_ref())
57 }
58}