use octocrate::GithubError;
use std::process::ExitStatus;
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("Failed to parse user config: {0}")]
WorkflowConfigError(String),
#[error("Error while running workflow: {0}")]
InternalRuntimeError(String),
#[error("Failed with exit status: {0:?}")]
Failed(ExitStatus),
#[error("IO error: {message}")]
IOError {
source: std::io::Error,
message: String,
},
#[error("Github API error: {message}")]
GithubError {
source: GithubError,
message: String,
},
#[error("Unsupported feature: {0}")]
UnsupportedFeature(String),
}
impl Error {
pub fn workflow_config_error<T: ToString>(message: T) -> Self {
Self::WorkflowConfigError(message.to_string())
}
pub fn internal_runtime_error<T: ToString>(message: T) -> Self {
Self::InternalRuntimeError(message.to_string())
}
pub fn io_error<T: ToString>(source: std::io::Error, message: T) -> Self {
Self::IOError {
source,
message: message.to_string(),
}
}
pub fn github_error<T: ToString>(source: GithubError, message: T) -> Self {
Self::GithubError {
source,
message: message.to_string(),
}
}
pub fn failed(exit_status: ExitStatus) -> Self {
Self::Failed(exit_status)
}
pub fn unsupported_feature<T: ToString>(message: T) -> Self {
Self::UnsupportedFeature(message.to_string())
}
}
impl PartialEq for Error {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::WorkflowConfigError(a), Self::WorkflowConfigError(b)) => a == b,
(Self::InternalRuntimeError(a), Self::InternalRuntimeError(b)) => a == b,
(Self::Failed(a), Self::Failed(b)) => a == b,
(Self::IOError { message: a, .. }, Self::IOError { message: b, .. }) => a == b,
(Self::GithubError { message: a, .. }, Self::GithubError { message: b, .. }) => a == b,
(Self::UnsupportedFeature(a), Self::UnsupportedFeature(b)) => a == b,
_ => false,
}
}
}