Add is_incomplete_input for LuneError struct

This commit is contained in:
Filip Tibell 2023-08-14 10:41:55 -05:00
parent 375f1b9334
commit 0ab32ffffd
No known key found for this signature in database
2 changed files with 18 additions and 11 deletions

View file

@ -13,20 +13,27 @@ use crate::lune::lua::stdio::formatting::pretty_format_luau_error;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct LuneError { pub struct LuneError {
message: String, message: String,
incomplete_input: bool,
} }
#[allow(dead_code)]
impl LuneError { impl LuneError {
pub(crate) fn new(message: String) -> Self { pub(crate) fn from_lua_error(error: LuaError, disable_colors: bool) -> Self {
Self { message } 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 { impl LuneError {
Self::new(pretty_format_luau_error(&error, true)) pub fn is_incomplete_input(&self) -> bool {
} self.incomplete_input
pub(crate) fn from_lua_error_plain(error: LuaError) -> Self {
Self::new(pretty_format_luau_error(&error, false))
} }
} }

View file

@ -56,7 +56,7 @@ impl Lune {
) -> Result<ExitCode, LuneError> { ) -> Result<ExitCode, LuneError> {
self.run_inner(script_name, script_contents) self.run_inner(script_name, script_contents)
.await .await
.map_err(LuneError::from_lua_error) .map_err(|err| LuneError::from_lua_error(err, false))
} }
async fn run_inner( async fn run_inner(
@ -87,7 +87,7 @@ impl Lune {
loop { loop {
let result = sched.resume_queue().await; let result = sched.resume_queue().await;
if let Some(err) = result.get_lua_error() { if let Some(err) = result.get_lua_error() {
eprintln!("{}", LuneError::from_lua_error(err)); eprintln!("{}", LuneError::from_lua_error(err, false));
got_error = true; got_error = true;
} }
if result.is_done() { if result.is_done() {