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 #[error("Failed to convert path to file:// url")]
35 FailedToConvertPathToFileUrl,
36 #[error(transparent)]
37 #[cfg(any(
38 target_os = "linux",
39 target_os = "dragonfly",
40 target_os = "freebsd",
41 target_os = "netbsd",
42 target_os = "openbsd"
43 ))]
44 Zbus(#[from] zbus::Error),
45}
46
47impl Serialize for Error {
48 fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
49 where
50 S: Serializer,
51 {
52 serializer.serialize_str(self.to_string().as_ref())
53 }
54}