parsec_tool/
error.rs

1// Copyright 2020 Contributors to the Parsec project.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Error definitions/handling.
5
6use thiserror::Error;
7
8/// Errors in parsec-tool.
9#[derive(Error, Debug)]
10pub enum Error {
11    /// Error emanating from the parsec_client crate.
12    #[error(transparent)]
13    IoError(#[from] std::io::Error),
14
15    /// Error emanating from the parsec_client crate.
16    #[error(transparent)]
17    ParsecClientError(#[from] parsec_client::error::Error),
18
19    /// Error emanating from the parsec_client::core::interface crate.
20    #[error(transparent)]
21    ParsecInterfaceError(#[from] parsec_client::core::interface::requests::ResponseStatus),
22
23    /// Error emanating from the parsec-tool.
24    #[error(transparent)]
25    ParsecToolError(#[from] ToolErrorKind),
26
27    /// Error emanating from the base64 crate.
28    #[error(transparent)]
29    Base64Decode(#[from] base64::DecodeError),
30
31    /// Error emanating from the rcgen create (can occur when creating certificates or CSRs)
32    #[error(transparent)]
33    RcgenError(#[from] rcgen::RcgenError),
34}
35
36/// Errors originating in the parsec-tool.
37#[derive(Error, Debug)]
38pub enum ToolErrorKind {
39    /// Operation not supported by the parsec-tool
40    #[error("Operation not supported by the parsec-tool")]
41    NotSupported,
42
43    /// They key was not created with the correct algorithm for this operation
44    #[error("They key was not created with the correct algorithm for this operation")]
45    WrongKeyAlgorithm,
46
47    /// Expected input data was not given
48    #[error("A command expected input data that was not given")]
49    NoInput,
50
51    /// Cannot serialise or deserialise data
52    #[error("Incorrect data format")]
53    IncorrectData,
54}
55
56/// A Result type with the Err variant set as a ParsecToolError
57pub type Result<T> = std::result::Result<T, Error>;