Skip to content

Commit

Permalink
feat: added better error for shell
Browse files Browse the repository at this point in the history
  • Loading branch information
matzxrr committed Jan 30, 2024
1 parent 514c7d1 commit 399313c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 0 additions & 2 deletions dotme-core/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use thiserror::Error;
pub enum RepoError {
#[error("repoistory config is invalid: {0}")]
InvalidRepoConfig(String),
#[error("loading config.toml file: {0}")]
ConfigLoadError(#[from] crate::config::ConfigLoadError),
#[error("git2: {0}")]
Git2Error(#[from] Git2Error),
#[error("unknown branch")]
Expand Down
9 changes: 6 additions & 3 deletions dotme-core/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use thiserror::Error;
pub enum ShellError {
#[error("Can't find the users shell, might not be supported")]
CannotFindShell,
#[error("Unknown shell '{0}'")]
UnknownShell(String),
}

type Result<T> = std::result::Result<T, ShellError>;
Expand Down Expand Up @@ -41,7 +43,7 @@ fn try_parse_shell(shell_path: &str) -> Result<ShellConfig> {
});
}
}
Err(ShellError::CannotFindShell)
Err(ShellError::UnknownShell(shell_path.to_owned()))
}

fn match_shell_to_config_file(shell: &str) -> Option<String> {
Expand Down Expand Up @@ -84,7 +86,8 @@ mod try_parse_shell_tests {
}
#[test]
fn it_shouldnt_load_unknown_shell() {
let shell = try_parse_shell("/usr/bin/unknown");
assert_eq!(shell, Err(ShellError::CannotFindShell));
let shell_path = String::from("/usr/bin/unknown");
let shell = try_parse_shell(&shell_path);
assert_eq!(shell, Err(ShellError::UnknownShell(shell_path)));
}
}

0 comments on commit 399313c

Please sign in to comment.