From f458f18ffa7efef7662b1f706233a177e8183ba3 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sun, 27 Nov 2022 22:35:17 +0800 Subject: [PATCH] Refine error message. --- src/bin/rhai-dbg.rs | 2 +- src/bin/rhai-repl.rs | 2 +- src/bin/rhai-run.rs | 2 +- src/types/error.rs | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/bin/rhai-dbg.rs b/src/bin/rhai-dbg.rs index a1ccc2b8..db929a4b 100644 --- a/src/bin/rhai-dbg.rs +++ b/src/bin/rhai-dbg.rs @@ -109,7 +109,7 @@ fn print_error(input: &str, mut err: EvalAltResult) { // Display position marker println!( "\x1b[31m{0:>1$}{err_line}\x1b[39m", - if i > 0 { " " } else { "^ " }, + if i > 0 { "| " } else { "^ " }, line_no.len() + pos.position().unwrap() + 1, ); } diff --git a/src/bin/rhai-repl.rs b/src/bin/rhai-repl.rs index cc2e71d2..ccb6af92 100644 --- a/src/bin/rhai-repl.rs +++ b/src/bin/rhai-repl.rs @@ -35,7 +35,7 @@ fn print_error(input: &str, mut err: EvalAltResult) { // Display position marker println!( "{0:>1$}{err_line}", - if i > 0 { " " } else { "^ " }, + if i > 0 { "| " } else { "^ " }, line_no.len() + pos.position().unwrap() + 1, ); } diff --git a/src/bin/rhai-run.rs b/src/bin/rhai-run.rs index a70c97cd..470bf42c 100644 --- a/src/bin/rhai-run.rs +++ b/src/bin/rhai-run.rs @@ -13,7 +13,7 @@ fn eprint_error(input: &str, mut err: EvalAltResult) { // Display position marker println!( "{0:>1$}{err_line}", - if i > 0 { " " } else { "^ " }, + if i > 0 { "| " } else { "^ " }, line_no.len() + pos.position().unwrap() + 1, ); } diff --git a/src/types/error.rs b/src/types/error.rs index 0f4c1cdc..c60edce5 100644 --- a/src/types/error.rs +++ b/src/types/error.rs @@ -135,20 +135,20 @@ impl fmt::Display for EvalAltResult { #[cfg(not(feature = "no_function"))] Self::ErrorInFunctionCall(s, src, err, ..) if crate::parser::is_anonymous_fn(s) => { - write!(f, "{err}\n| in closure call")?; + write!(f, "{err}\nin closure call")?; if !src.is_empty() { write!(f, " @ '{src}'")?; } } Self::ErrorInFunctionCall(s, src, err, ..) => { - write!(f, "{err}\n| in call to function '{s}'")?; + write!(f, "{err}\nin call to function '{s}'")?; if !src.is_empty() { write!(f, " @ '{src}'")?; } } - Self::ErrorInModule(s, err, ..) if s.is_empty() => write!(f, "{err}\n| in module")?, - Self::ErrorInModule(s, err, ..) => write!(f, "{err}\n| in module '{s}'")?, + Self::ErrorInModule(s, err, ..) if s.is_empty() => write!(f, "{err}\nin module")?, + Self::ErrorInModule(s, err, ..) => write!(f, "{err}\nin module '{s}'")?, Self::ErrorVariableExists(s, ..) => write!(f, "Variable already defined: {s}")?, Self::ErrorForbiddenVariable(s, ..) => write!(f, "Forbidden variable name: {s}")?,