Skip to main content

tauri_plugin_cli/
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
7/// Errors that can be returned from the CLI plugin's commands.
8#[derive(Debug, thiserror::Error)]
9pub enum Error {
10    /// Parsing the process arguments against the CLI definition in `tauri.conf.json` failed,
11    /// e.g. because a required argument is missing or an unknown flag was passed.
12    #[error("failed to parse arguments: {0}")]
13    ParseCli(#[from] clap::Error),
14}
15
16impl Serialize for Error {
17    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
18    where
19        S: Serializer,
20    {
21        serializer.serialize_str(self.to_string().as_ref())
22    }
23}
24
25/// Alias for a [`std::result::Result`] with the error type [`Error`].
26pub type Result<T> = std::result::Result<T, Error>;