refactor: Add 'AppError' to allow cleaner propagation of different errors

pull/1/head
sgoudham 2 years ago
parent db5f27c1ad
commit c632965a2a
Signed by: hammy
GPG Key ID: 44E818FD5457EEA4

@ -0,0 +1,34 @@
#[derive(Debug, PartialEq)]
pub enum AppError {
CommandFailedToExecute(String),
CommandError(String),
MissingGitRepository(String),
MissingGitRemote(String),
InvalidGitUrl(String),
InvalidUtf8(String),
}
impl From<std::io::Error> for AppError {
fn from(error: std::io::Error) -> Self {
AppError::CommandFailedToExecute(error.to_string())
}
}
impl From<std::str::Utf8Error> for AppError {
fn from(error: std::str::Utf8Error) -> Self {
AppError::InvalidUtf8(error.to_string())
}
}
impl AppError {
pub fn print(&self) -> &String {
match self {
AppError::CommandFailedToExecute(str)
| AppError::MissingGitRepository(str)
| AppError::MissingGitRemote(str)
| AppError::CommandError(str)
| AppError::InvalidGitUrl(str)
| AppError::InvalidUtf8(str) => str,
}
}
}
Loading…
Cancel
Save