use crate::ForgeKind;
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
Forge(processkit::Error),
Unsupported {
forge: ForgeKind,
operation: &'static str,
},
}
impl Error {
pub fn is_transient_fetch_error(&self) -> bool {
matches!(self, Error::Forge(e) if vcs_cli_support::is_transient_fetch_error(e))
}
pub fn is_unsupported(&self) -> bool {
matches!(self, Error::Unsupported { .. })
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::Forge(e) => write!(f, "{e}"),
Error::Unsupported { forge, operation } => {
write!(f, "{} does not support `{operation}`", forge.as_str())
}
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Forge(e) => Some(e),
Error::Unsupported { .. } => None,
}
}
}
impl From<processkit::Error> for Error {
fn from(e: processkit::Error) -> Self {
Error::Forge(e)
}
}
pub type Result<T> = std::result::Result<T, Error>;