From 4edb7ee844544df54006c71dec5e1a49c02a9e48 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 5 Feb 2025 14:06:36 +0100 Subject: [PATCH] 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. --- src/visudo/mod.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/visudo/mod.rs b/src/visudo/mod.rs index 9c75a37c5..2ce2bc944 100644 --- a/src/visudo/mod.rs +++ b/src/visudo/mod.rs @@ -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); + } else { + writeln!(stderr, "syntax error: {message}")?; + } } writeln!(stderr)?;