Skip to content

Commit

Permalink
Improve visudo errors
Browse files Browse the repository at this point in the history
This now shows errors in the same format as sudo, which includes the
location of the error as well as the line where the error happened.
  • Loading branch information
bjorn3 committed Feb 5, 2025
1 parent 4f7983f commit 4edb7ee
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/visudo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,18 @@ fn edit_sudoers_file(

writeln!(stderr, "The provided sudoers file format is not recognized or contains syntax errors. Please review:\n")?;

for crate::sudoers::Error { message, .. } in errors {
writeln!(stderr, "syntax error: {message}")?;
for crate::sudoers::Error {
source,
location,
message,
} in errors
{
let path = source.as_deref().unwrap_or(sudoers_path);
if let Some(range) = location {
crate::sudo::diagnostic::cited_error(&format!("{message}"), range, path);

Check failure on line 268 in src/visudo/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

useless use of `format!`
} else {
writeln!(stderr, "syntax error: {message}")?;
}
}

writeln!(stderr)?;
Expand Down

0 comments on commit 4edb7ee

Please sign in to comment.