Skip to main content

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/// Errors returned by the shell plugin.
10#[derive(Debug, thiserror::Error)]
11pub enum Error {
12    #[error(transparent)]
13    Io(#[from] std::io::Error),
14    /// The path of the current executable has no parent directory,
15    /// so the path of a sidecar program could not be resolved.
16    #[error("current executable path has no parent")]
17    CurrentExeHasNoParent,
18    #[error(transparent)]
19    Scope(#[from] crate::scope::Error),
20    /// Sidecar not allowed by the configuration.
21    #[error("sidecar not configured under `tauri.conf.json > bundle > externalBin`: {0}")]
22    SidecarNotAllowed(PathBuf),
23    /// Program not allowed by the scope.
24    #[error("program not allowed on the configured shell scope: {0}")]
25    ProgramNotAllowed(PathBuf),
26    /// The `encoding` spawn option is neither `raw` nor a label of a known character encoding.
27    #[error("unknown encoding {0}")]
28    UnknownEncoding(String),
29    /// JSON error.
30    #[error(transparent)]
31    Json(#[from] serde_json::Error),
32    /// Utf8 error.
33    #[error(transparent)]
34    Utf8(#[from] std::string::FromUtf8Error),
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}