mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2025-01-07 10:26:45 +03:00
Merge pull request #1513 from gitbutlerapp/refactor-git2-error-handling
Refactor git2 error handling
This commit is contained in:
commit
b6bd0a4106
@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user