tauri_plugin_haptics/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 [`Error`].
8pub type Result<T> = std::result::Result<T, Error>;
9
10// TODO: Improve Error handling (different typed errors instead of one (stringified) PluginInvokeError for all mobile errors)
11
12/// Errors returned by the haptics APIs.
13#[derive(Debug, thiserror::Error)]
14#[cfg_attr(feature = "specta", derive(specta::Type))]
15pub enum Error {
16 /// The call to the Android or iOS plugin implementation failed, either because the
17 /// arguments could not be serialized, the response could not be deserialized, or the
18 /// native side rejected the call. Only produced on Android and iOS.
19 #[cfg(mobile)]
20 #[error(transparent)]
21 PluginInvoke(
22 #[cfg_attr(feature = "specta", specta(skip))]
23 #[from]
24 tauri::plugin::mobile::PluginInvokeError,
25 ),
26}
27
28impl Serialize for Error {
29 fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
30 where
31 S: Serializer,
32 {
33 serializer.serialize_str(self.to_string().as_ref())
34 }
35}