tauri_plugin_deep_link/error.rs
1// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
2// SPDX-License-Identifier: Apache-2.0
3// SPDX-License-Identifier: MIT
4
5use serde::{Serialize, ser::Serializer};
6
7/// Alias for a [`Result`](std::result::Result) with the error type [`Error`].
8pub type Result<T> = std::result::Result<T, Error>;
9
10/// The error type for this plugin.
11#[derive(Debug, thiserror::Error)]
12pub enum Error {
13 /// The requested operation (usually registering or unregistering a protocol scheme at
14 /// runtime) is not supported on the current platform.
15 #[error("unsupported platform")]
16 UnsupportedPlatform,
17 /// Transparent wrapper around an [`std::io::Error`].
18 #[error(transparent)]
19 Io(#[from] std::io::Error),
20 /// Transparent wrapper around a [`tauri::Error`].
21 #[error(transparent)]
22 Tauri(#[from] tauri::Error),
23 /// Transparent wrapper around a [`windows_result::Error`]. Only used on Windows.
24 #[cfg(target_os = "windows")]
25 #[error(transparent)]
26 Windows(#[from] windows_result::Error),
27 /// Transparent wrapper around an [`ini::Error`], returned when reading or writing the
28 /// `.desktop` file used to register a protocol scheme. Only used on Linux.
29 #[cfg(target_os = "linux")]
30 #[error(transparent)]
31 Ini(#[from] ini::Error),
32 /// Transparent wrapper around an [`ini::ParseError`], returned when parsing the
33 /// `.desktop` file used to register a protocol scheme. Only used on Linux.
34 #[cfg(target_os = "linux")]
35 #[error(transparent)]
36 ParseIni(#[from] ini::ParseError),
37 /// Transparent wrapper around a [`tauri::plugin::mobile::PluginInvokeError`], returned
38 /// when the underlying mobile plugin invocation fails. Only used on mobile.
39 #[cfg(mobile)]
40 #[error(transparent)]
41 PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
42}
43
44// TODO(v3): change this into an error in v3,
45// see <https://github.com/tauri-apps/plugins-workspace/pull/2970#issuecomment-3244660138>.
46#[inline]
47#[cfg(target_os = "linux")]
48pub(crate) fn inspect_command_error<'a>(command: &'a str) -> impl Fn(&std::io::Error) + 'a {
49 move |e| {
50 tracing::error!("Failed to run OS command `{command}`: {e}");
51 }
52}
53
54impl Serialize for Error {
55 fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
56 where
57 S: Serializer,
58 {
59 serializer.serialize_str(self.to_string().as_ref())
60 }
61}