Skip to main content

tauri_plugin_python/
error.rs

1//  Tauri Python Plugin
2//  © Copyright 2024, by Marco Mengelkoch
3//  Licensed under MIT License, see License file for more details
4//  git clone https://github.com/marcomq/tauri-plugin-python
5use async_py::PyRunnerError;
6
7use serde::{ser::Serializer, Serialize};
8
9pub type Result<T> = std::result::Result<T, Error>;
10
11#[derive(Debug, thiserror::Error)]
12pub enum Error {
13    #[error("Error: {0}")]
14    String(String),
15    #[error(transparent)]
16    Io(#[from] std::io::Error),
17    #[cfg(mobile)]
18    #[error(transparent)]
19    PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
20    #[error(transparent)]
21    PyRunner(#[from] PyRunnerError),
22}
23
24impl Serialize for Error {
25    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
26    where
27        S: Serializer,
28    {
29        serializer.serialize_str(self.to_string().as_ref())
30    }
31}
32
33impl From<&str> for Error {
34    fn from(error: &str) -> Self {
35        Error::String(error.into())
36    }
37}
38
39impl From<tauri::Error> for Error {
40    fn from(error: tauri::Error) -> Self {
41        Error::String(error.to_string())
42    }
43}