Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/common/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl fmt::Display for Error {
}
Ok(())
}
Error::Configuration(e) => write!(f, "invalid configuration: {e}"),
Error::Configuration(e) => write!(f, "{e}"),
Error::Options(e) => write!(f, "{e}"),
Error::Pam(e) => write!(f, "{e}"),
Error::Io(location, e) => {
Expand Down
20 changes: 18 additions & 2 deletions src/sudo/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,24 @@ pub(super) use edit::run_edit;
fn read_sudoers() -> Result<Sudoers, Error> {
let sudoers_path = &super::candidate_sudoers_file();

let (sudoers, syntax_errors) =
Sudoers::open(sudoers_path).map_err(|e| Error::Configuration(format!("{e}")))?;
let (sudoers, syntax_errors) = Sudoers::open(sudoers_path).map_err(|e| {
// Provide a more helpful error message when the sudoers file is missing
if e.kind() == std::io::ErrorKind::NotFound {
Error::Configuration(format!(
"sudoers file not found: {}\n\
\n\
The sudoers file is required for sudo-rs to function. Please ensure:\n\
- The file exists at the expected location\n\
- You have the necessary permissions to read it\n\
- If setting up sudo-rs for the first time, create a sudoers file with appropriate permissions\n\
\n\
For more information, see the sudo-rs documentation.",
sudoers_path.display()
))
} else {
Error::Configuration(format!("invalid configuration: {e}"))
}
})?;

for crate::sudoers::Error {
source,
Expand Down
Loading