Merge pull request #1513 from gitbutlerapp/refactor-git2-error-handling

Refactor git2 error handling
This commit is contained in:
Nikita Galaiko 2023-11-06 15:56:59 +01:00 committed by GitHub
commit b6bd0a4106
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,8 +6,6 @@ pub enum Error {
NotFound(Box<dyn std::error::Error + Send + Sync>),
#[error("authentication failed")]
AuthenticationFailed(Box<dyn std::error::Error + Send + Sync>),
#[error("ssh key error: {0}")]
SshKeyError(Box<dyn std::error::Error + Send + Sync>),
#[error("sign error: {0}")]
SignError(Box<dyn std::error::Error + Send + Sync>),
#[error("remote url error: {0}")]
@ -21,19 +19,20 @@ pub enum Error {
impl From<git2::Error> for Error {
fn from(err: git2::Error) -> Self {
if err.class() == git2::ErrorClass::Ssh && err.code() == git2::ErrorCode::GenericError {
return Error::SshKeyError(err.into());
}
match err.code() {
git2::ErrorCode::NotFound => Error::NotFound(err.into()),
git2::ErrorCode::Auth => Error::AuthenticationFailed(err.into()),
_ => Error::Other(err.into()),
Error::AuthenticationFailed(err.into())
} else {
match err.code() {
git2::ErrorCode::NotFound => Error::NotFound(err.into()),
git2::ErrorCode::Auth => Error::AuthenticationFailed(err.into()),
_ => Error::Other(err.into()),
}
}
}
}
impl From<keys::SignError> for Error {
fn from(err: keys::SignError) -> Self {
Error::SshKeyError(err.into())
Error::SignError(err.into())
}
}