1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use regex::Error as RegexError;
use std::{env, ffi::OsString, fmt::Display, num::ParseIntError};
use thiserror::Error;

#[derive(Error, Debug)]
pub enum Error {
    /// Unable to acquire the child process' standard input to write the commit data for signing
    #[error("Failed to acquire standard input handler")]
    Stdin,

    /// Unable to retrieve the signed data from the child process
    #[error("Failed to get output of signing process call: {0}")]
    Stdout(String),

    #[error("{0}")]
    GpgError(String),
    #[error("Environment variable PCU_BRANCH not set")]
    EnvVarBranchNotSet,
    #[error("Environment variable specified in PCU_BRANCH not found")]
    EnvVarBranchNotFound,
    #[error("Environment variable PCU_PULL_REQUEST not set")]
    EnvVarPullRequestNotSet,
    #[error("Environment variable specified in PCU_PULL_REQUEST not found")]
    EnvVarPullRequestNotFound,
    #[error("Unreleased section not found in change log")]
    NoUnreleasedSection,
    #[error("Command not set")]
    CommandNotSet,
    #[error("Tag not found {0:?}")]
    TagNotFound(String),
    #[error("Invalid version string")]
    InvalidVersion(String),
    #[error("Default change log file name not set")]
    DefaultChangeLogNotSet,
    #[error("Invalid path for changelog file {0:?}")]
    InvalidPath(OsString),
    #[error("Regex string is not valid.")]
    InvalidRegex,
    #[error("Keep a changelog says: {0}")]
    KeepAChangelog(String),
    #[error("No GitHub API private key found")]
    NoGitHubAPIPrivateKey,
    #[error("No GitHub API Authorisation found")]
    NoGitHubAPIAuth,
    #[error("On default branch")]
    OnDefaultBranch,
    #[error("Unknown format for pull request: {0}")]
    UknownPullRequestFormat(String),
    #[error("No default changelog file found")]
    NoChangeLogFileFound,
    #[error("ParseInt says: {0:?}")]
    ParseInt(#[from] ParseIntError),
    #[error("Octocrate says: {0:?}")]
    Octocrate(#[from] octocrate::Error),
    #[error("GraphQL says: {0:?}")]
    GraphQL(#[from] GraphQLWrapper),
    #[error("Url says: {0:?}")]
    UrlParse(#[from] url::ParseError),
    #[error("Git2 says: {0:?}")]
    Git2(#[from] git2::Error),
    #[error("env var says: {0:?}")]
    EnvVar(#[from] env::VarError),
    #[error("io error says: {0:?}")]
    IO(#[from] std::io::Error),
    #[error("utf8 error says: {0:?}")]
    Utf8(#[from] std::str::Utf8Error),
    #[error("config error says: {0:?}")]
    Config(#[from] config::ConfigError),
    #[error("regex error says: {0:?}")]
    Regex(#[from] RegexError),
}

#[derive(Debug)]
pub struct GraphQLWrapper(gql_client::GraphQLError);

impl std::error::Error for GraphQLWrapper {
    fn description(&self) -> &str {
        "A GraphQL error occurred"
    }

    fn cause(&self) -> Option<&dyn std::error::Error> {
        None
    }
}

impl From<gql_client::GraphQLError> for GraphQLWrapper {
    fn from(err: gql_client::GraphQLError) -> Self {
        GraphQLWrapper(err)
    }
}

impl Display for GraphQLWrapper {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}