Skip to content

Commit b419ed5

Browse files
bjorn3squell
authored andcommitted
Improve visudo errors
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.
1 parent 4f7983f commit b419ed5

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/visudo/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,14 @@ fn edit_sudoers_file(
257257

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

260-
for crate::sudoers::Error { message, .. } in errors {
261-
writeln!(stderr, "syntax error: {message}")?;
260+
for crate::sudoers::Error {
261+
message,
262+
source,
263+
location,
264+
} in errors
265+
{
266+
let path = source.as_deref().unwrap_or(sudoers_path);
267+
diagnostic::diagnostic!("syntax error: {message}", path @ location);
262268
}
263269

264270
writeln!(stderr)?;

0 commit comments

Comments
 (0)