tauri_plugin_shell/
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)]
10pub enum Error {
11    #[cfg(mobile)]
12    #[error(transparent)]
13    PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
14    #[error(transparent)]
15    Io(#[from] std::io::Error),
16    #[error("current executable path has no parent")]
17    CurrentExeHasNoParent,
18    #[error("unknown program {0}")]
19    UnknownProgramName(String),
20    #[error(transparent)]
21    Scope(#[from] crate::scope::Error),
22    /// Sidecar not allowed by the configuration.
23    #[error("sidecar not configured under `tauri.conf.json > bundle > externalBin`: {0}")]
24    SidecarNotAllowed(PathBuf),
25    /// Program not allowed by the scope.
26    #[error("program not allowed on the configured shell scope: {0}")]
27    ProgramNotAllowed(PathBuf),
28    #[error("unknown encoding {0}")]
29    UnknownEncoding(String),
30    /// JSON error.
31    #[error(transparent)]
32    Json(#[from] serde_json::Error),
33    /// Utf8 error.
34    #[error(transparent)]
35    Utf8(#[from] std::string::FromUtf8Error),
36}
37
38impl Serialize for Error {
39    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
40    where
41        S: Serializer,
42    {
43        serializer.serialize_str(self.to_string().as_ref())
44    }
45}