tauri_plugin_dialog/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 `Result<T, Error>` used throughout this crate.
8pub type Result<T> = std::result::Result<T, Error>;
9
10/// Errors that can occur while showing or interacting with a dialog.
11#[derive(Debug, thiserror::Error)]
12#[non_exhaustive]
13pub enum Error {
14 /// An error forwarded from the Tauri core.
15 #[error(transparent)]
16 Tauri(#[from] tauri::Error),
17 /// An I/O error, for example while resolving a picked path.
18 #[error(transparent)]
19 Io(#[from] std::io::Error),
20 /// Forwarding a request to, or receiving a response from, the mobile plugin failed.
21 #[cfg(mobile)]
22 #[error(transparent)]
23 PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
24 /// The folder picker was requested through the `open` command, but folder picking is not implemented on mobile.
25 #[cfg(mobile)]
26 #[error("Folder picker is not implemented on mobile")]
27 FolderPickerNotImplemented,
28 /// An error forwarded from the `fs` plugin, returned when granting filesystem scope to a picked path fails.
29 #[error(transparent)]
30 Fs(#[from] tauri_plugin_fs::Error),
31}
32
33impl Serialize for Error {
34 fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
35 where
36 S: Serializer,
37 {
38 serializer.serialize_str(self.to_string().as_ref())
39 }
40}