tauri_plugin_fs/
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 std::path::PathBuf;
6
7use serde::{Serialize, Serializer};
8
9#[derive(Debug, thiserror::Error)]
10#[non_exhaustive]
11pub enum Error {
12    #[error(transparent)]
13    Json(#[from] serde_json::Error),
14    #[error(transparent)]
15    Tauri(#[from] tauri::Error),
16    #[error(transparent)]
17    Io(#[from] std::io::Error),
18    #[error("forbidden path: {0}")]
19    PathForbidden(PathBuf),
20    /// Invalid glob pattern.
21    #[error("invalid glob pattern: {0}")]
22    GlobPattern(#[from] glob::PatternError),
23    /// Watcher error.
24    #[cfg(feature = "watch")]
25    #[error(transparent)]
26    Watch(#[from] notify::Error),
27    #[cfg(target_os = "android")]
28    #[error(transparent)]
29    PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
30    #[error("URL is not a valid path")]
31    InvalidPathUrl,
32    #[error("Unsafe PathBuf: {0}")]
33    UnsafePathBuf(&'static str),
34}
35
36impl Serialize for Error {
37    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
38    where
39        S: Serializer,
40    {
41        serializer.serialize_str(self.to_string().as_ref())
42    }
43}