1use std::fmt;
6
7#[derive(Debug)]
9pub struct SetupError(Box<dyn std::error::Error>);
10
11impl From<Box<dyn std::error::Error>> for SetupError {
12 fn from(error: Box<dyn std::error::Error>) -> Self {
13 Self(error)
14 }
15}
16
17unsafe impl Send for SetupError {}
20unsafe impl Sync for SetupError {}
21
22impl fmt::Display for SetupError {
23 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24 self.0.fmt(f)
25 }
26}
27
28impl std::error::Error for SetupError {}
29
30#[derive(Debug, thiserror::Error)]
32#[non_exhaustive]
33pub enum Error {
34 #[error("runtime error: {0}")]
36 Runtime(#[from] tauri_runtime::Error),
37 #[error("a window with label `{0}` already exists")]
39 WindowLabelAlreadyExists(String),
40 #[error("a webview with label `{0}` already exists")]
42 WebviewLabelAlreadyExists(String),
43 #[error("cannot reparent when using a WebviewWindow")]
45 CannotReparentWebviewWindow,
46 #[error("asset not found: {0}")]
48 AssetNotFound(String),
49 #[error("JSON error: {0}")]
51 Json(#[from] serde_json::Error),
52 #[error("{0}")]
54 Io(#[from] std::io::Error),
55 #[error("invalid icon: {0}")]
57 InvalidIcon(std::io::Error),
58 #[error("invalid args `{1}` for command `{0}`: {2}")]
60 InvalidArgs(&'static str, &'static str, serde_json::Error),
61 #[error("error encountered during setup hook: {0}")]
63 Setup(SetupError),
64 #[error("failed to initialize plugin `{0}`: {1}")]
66 PluginInitialization(String, String),
67 #[error("invalid url: {0}")]
70 InvalidUrl(url::ParseError),
71 #[error(transparent)]
73 JoinError(#[from] tokio::task::JoinError),
74 #[cfg(feature = "isolation")]
76 #[error("isolation pattern error: {0}")]
77 IsolationPattern(#[from] tauri_utils::pattern::isolation::Error),
78 #[error("invalid window url: {0}")]
80 InvalidWebviewUrl(&'static str),
81 #[error("invalid glob pattern: {0}")]
83 GlobPattern(#[from] glob::PatternError),
84 #[cfg(any(feature = "image-png", feature = "image-ico"))]
86 #[error("failed to process image: {0}")]
87 Image(#[from] image::error::ImageError),
88 #[error("Unexpected `raw_window_handle` for the current platform")]
90 InvalidWindowHandle,
91 #[cfg(target_os = "android")]
93 #[error("jni error: {0}")]
94 Jni(#[from] jni::errors::Error),
95 #[error("failed to receive message")]
97 FailedToReceiveMessage,
98 #[error("menu error: {0}")]
100 #[cfg(desktop)]
101 Menu(#[from] muda::Error),
102 #[error(transparent)]
104 #[cfg(desktop)]
105 BadMenuIcon(#[from] muda::BadIcon),
106 #[error("tray icon error: {0}")]
108 #[cfg(all(desktop, feature = "tray-icon"))]
109 #[cfg_attr(docsrs, doc(cfg(all(desktop, feature = "tray-icon"))))]
110 Tray(#[from] tray_icon::Error),
111 #[error(transparent)]
113 #[cfg(all(desktop, feature = "tray-icon"))]
114 #[cfg_attr(docsrs, doc(cfg(all(desktop, feature = "tray-icon"))))]
115 BadTrayIcon(#[from] tray_icon::BadIcon),
116 #[error("path does not have a parent")]
118 NoParent,
119 #[error("path does not have an extension")]
121 NoExtension,
122 #[error("path does not have a basename")]
124 NoBasename,
125 #[error("failed to read current dir: {0}")]
127 CurrentDir(std::io::Error),
128 #[cfg(not(target_os = "android"))]
130 #[error("unknown path")]
131 UnknownPath,
132 #[cfg(target_os = "android")]
134 #[error(transparent)]
135 PluginInvoke(#[from] crate::plugin::mobile::PluginInvokeError),
136 #[error("window not found")]
138 WindowNotFound,
139 #[error("The resource id {0} is invalid.")]
141 BadResourceId(crate::resources::ResourceId),
142 #[error(transparent)]
144 Anyhow(#[from] anyhow::Error),
145 #[error("webview not found")]
147 WebviewNotFound,
148 #[error("this feature requires the `unstable` flag on Cargo.toml")]
150 UnstableFeatureNotSupported,
151 #[error("error deserializing scope: {0}")]
153 CannotDeserializeScope(Box<dyn std::error::Error + Send + Sync>),
154 #[error(transparent)]
156 RawHandleError(#[from] raw_window_handle::HandleError),
157 #[error("unable to generate random bytes from the operating system: {0}")]
159 Csprng(getrandom::Error),
160 #[error("bad __TAURI_INVOKE_KEY__ value received in ipc message")]
162 InvokeKey,
163 #[error("only alphanumeric, '-', '/', ':', '_' permitted for event names: {0:?}")]
165 IllegalEventName(String),
166 #[error(transparent)]
168 TokioOneshotRecv(#[from] tokio::sync::oneshot::error::RecvError),
169}
170
171impl From<getrandom::Error> for Error {
172 fn from(value: getrandom::Error) -> Self {
173 Self::Csprng(value)
174 }
175}
176
177pub type Result<T> = std::result::Result<T, Error>;
179
180#[cfg(test)]
181mod tests {
182 #[test]
183 fn error_is_send_sync() {
184 crate::test_utils::assert_send::<super::Error>();
185 crate::test_utils::assert_sync::<super::Error>();
186 }
187}