tauri_plugin_store/
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, Serializer};
6
7pub type Result<T> = std::result::Result<T, Error>;
8
9/// The error types.
10#[derive(thiserror::Error, Debug)]
11#[non_exhaustive]
12pub enum Error {
13    #[error("Failed to serialize store. {0}")]
14    Serialize(Box<dyn std::error::Error + Send + Sync>),
15    #[error("Failed to deserialize store. {0}")]
16    Deserialize(Box<dyn std::error::Error + Send + Sync>),
17    /// JSON error.
18    #[error(transparent)]
19    Json(#[from] serde_json::Error),
20    /// IO error.
21    #[error(transparent)]
22    Io(#[from] std::io::Error),
23    // /// Store already exists
24    // #[error("Store at \"{0}\" already exists")]
25    // AlreadyExists(PathBuf),
26    /// Serialize function not found
27    #[error("Serialize Function \"{0}\" not found")]
28    SerializeFunctionNotFound(String),
29    /// Deserialize function not found
30    #[error("Deserialize Function \"{0}\" not found")]
31    DeserializeFunctionNotFound(String),
32    /// Some Tauri API failed
33    #[error(transparent)]
34    Tauri(#[from] tauri::Error),
35}
36
37impl Serialize for Error {
38    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
39    where
40        S: Serializer,
41    {
42        serializer.serialize_str(self.to_string().as_ref())
43    }
44}