pcu_lib/
error.rs

1use regex::Error as RegexError;
2use std::{env, ffi::OsString, fmt::Display, num::ParseIntError};
3use thiserror::Error;
4
5#[derive(Error, Debug)]
6pub enum Error {
7    /// Unable to acquire the child process' standard input to write the commit data for signing
8    #[error("Failed to acquire standard input handler")]
9    Stdin,
10
11    /// Unable to retrieve the signed data from the child process
12    #[error("Failed to get output of signing process call: {0}")]
13    Stdout(String),
14
15    #[error("{0}")]
16    GpgError(String),
17    #[error("Environment variable PCU_BRANCH not set")]
18    EnvVarBranchNotSet,
19    #[error("Environment variable specified in PCU_BRANCH not found")]
20    EnvVarBranchNotFound,
21    #[error("Environment variable PCU_PULL_REQUEST not set")]
22    EnvVarPullRequestNotSet,
23    #[error("Environment variable specified in PCU_PULL_REQUEST not found")]
24    EnvVarPullRequestNotFound,
25    #[error("Unreleased section not found in change log")]
26    NoUnreleasedSection,
27    #[error("Command not set")]
28    CommandNotSet,
29    #[error("Tag not found {0:?}")]
30    TagNotFound(String),
31    #[error("Invalid version string")]
32    InvalidVersion(String),
33    #[error("Default change log file name not set")]
34    DefaultChangeLogNotSet,
35    #[error("Invalid path for changelog file {0:?}")]
36    InvalidPath(OsString),
37    #[error("Regex string is not valid.")]
38    InvalidRegex,
39    #[error("Keep a changelog says: {0}")]
40    KeepAChangelog(String),
41    #[error("No GitHub API private key found")]
42    NoGitHubAPIPrivateKey,
43    #[error("No GitHub API Authorisation found")]
44    NoGitHubAPIAuth,
45    #[error("On default branch")]
46    OnDefaultBranch,
47    #[error("Unknown format for pull request: {0}")]
48    UknownPullRequestFormat(String),
49    #[error("No default changelog file found")]
50    NoChangeLogFileFound,
51    #[error("ParseInt says: {0:?}")]
52    ParseInt(#[from] ParseIntError),
53    #[error("Octocrate says: {0:?}")]
54    Octocrate(#[from] octocrate::Error),
55    #[error("GraphQL says: {0:?}")]
56    GraphQL(#[from] GraphQLWrapper),
57    #[error("Url says: {0:?}")]
58    UrlParse(#[from] url::ParseError),
59    #[error("Git2 says: {0:?}")]
60    Git2(#[from] git2::Error),
61    #[error("env var says: {0:?}")]
62    EnvVar(#[from] env::VarError),
63    #[error("io error says: {0:?}")]
64    IO(#[from] std::io::Error),
65    #[error("utf8 error says: {0:?}")]
66    Utf8(#[from] std::str::Utf8Error),
67    #[error("config error says: {0:?}")]
68    Config(#[from] config::ConfigError),
69    #[error("regex error says: {0:?}")]
70    Regex(#[from] RegexError),
71    #[error("cargo_toml error says: {0:?}")]
72    Toml(#[from] cargo_toml::Error),
73}
74
75#[derive(Debug)]
76pub struct GraphQLWrapper(gql_client::GraphQLError);
77
78impl std::error::Error for GraphQLWrapper {
79    fn description(&self) -> &str {
80        "A GraphQL error occurred"
81    }
82
83    fn cause(&self) -> Option<&dyn std::error::Error> {
84        None
85    }
86}
87
88impl From<gql_client::GraphQLError> for GraphQLWrapper {
89    fn from(err: gql_client::GraphQLError) -> Self {
90        GraphQLWrapper(err)
91    }
92}
93
94impl Display for GraphQLWrapper {
95    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
96        write!(f, "{}", self.0)
97    }
98}