diff --git a/src/lune/error.rs b/src/lune/error.rs index eb3ec56..5369e21 100644 --- a/src/lune/error.rs +++ b/src/lune/error.rs @@ -13,20 +13,27 @@ use crate::lune::lua::stdio::formatting::pretty_format_luau_error; #[derive(Debug, Clone)] pub struct LuneError { message: String, + incomplete_input: bool, } -#[allow(dead_code)] impl LuneError { - pub(crate) fn new(message: String) -> Self { - Self { message } + pub(crate) fn from_lua_error(error: LuaError, disable_colors: bool) -> Self { + Self { + message: pretty_format_luau_error(&error, !disable_colors), + incomplete_input: matches!( + error, + LuaError::SyntaxError { + incomplete_input: true, + .. + } + ), + } } +} - pub(crate) fn from_lua_error(error: LuaError) -> Self { - Self::new(pretty_format_luau_error(&error, true)) - } - - pub(crate) fn from_lua_error_plain(error: LuaError) -> Self { - Self::new(pretty_format_luau_error(&error, false)) +impl LuneError { + pub fn is_incomplete_input(&self) -> bool { + self.incomplete_input } } diff --git a/src/lune/mod.rs b/src/lune/mod.rs index e0eeec6..f4f49c8 100644 --- a/src/lune/mod.rs +++ b/src/lune/mod.rs @@ -56,7 +56,7 @@ impl Lune { ) -> Result { self.run_inner(script_name, script_contents) .await - .map_err(LuneError::from_lua_error) + .map_err(|err| LuneError::from_lua_error(err, false)) } async fn run_inner( @@ -87,7 +87,7 @@ impl Lune { loop { let result = sched.resume_queue().await; if let Some(err) = result.get_lua_error() { - eprintln!("{}", LuneError::from_lua_error(err)); + eprintln!("{}", LuneError::from_lua_error(err, false)); got_error = true; } if result.is_done() {