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)]
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
}
}

View file

@ -56,7 +56,7 @@ impl Lune {
) -> Result<ExitCode, LuneError> {
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() {