Skip to main content

tauri_plugin_notification/
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 [`std::result::Result`] with the error type set to [`Error`].
8pub type Result<T> = std::result::Result<T, Error>;
9
10/// Errors returned by the notification plugin.
11///
12/// The error is serialized to its [`Display`](std::fmt::Display) string when it crosses the IPC boundary.
13#[derive(Debug, thiserror::Error)]
14pub enum Error {
15    /// An I/O operation failed, e.g. resolving the path of the running executable on Windows.
16    #[error(transparent)]
17    Io(#[from] std::io::Error),
18    /// Failed to run a command on the mobile plugin implementation (Kotlin on Android, Swift on iOS).
19    ///
20    /// Only available on mobile.
21    #[cfg(mobile)]
22    #[error(transparent)]
23    PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
24}
25
26impl Serialize for Error {
27    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
28    where
29        S: Serializer,
30    {
31        serializer.serialize_str(self.to_string().as_ref())
32    }
33}