Skip to content

Commit

Permalink
refactor: Add 'AppError' to allow cleaner propagation of different er…
Browse files Browse the repository at this point in the history
…rors
  • Loading branch information
sgoudham committed Jun 8, 2022
1 parent db5f27c commit c632965
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/error.rs
@@ -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,
}
}
}

0 comments on commit c632965

Please sign in to comment.