mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 13:00:37 +00:00
Add is_incomplete_input for LuneError struct
This commit is contained in:
parent
375f1b9334
commit
0ab32ffffd
2 changed files with 18 additions and 11 deletions
|
@ -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 {
|
|
||||||
Self::new(pretty_format_luau_error(&error, true))
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn from_lua_error_plain(error: LuaError) -> Self {
|
impl LuneError {
|
||||||
Self::new(pretty_format_luau_error(&error, false))
|
pub fn is_incomplete_input(&self) -> bool {
|
||||||
|
self.incomplete_input
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
Loading…
Reference in a new issue