From b69f824b57816f6fb38517583fd8eccd58a4169f Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Sat, 19 Aug 2023 17:15:24 -0500 Subject: [PATCH] Pretty-print lua errors --- src/lune/error.rs | 9 +++++++++ src/lune/scheduler/impl_runner.rs | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/lune/error.rs b/src/lune/error.rs index dcb9222..1999877 100644 --- a/src/lune/error.rs +++ b/src/lune/error.rs @@ -62,6 +62,15 @@ impl From for LuneError { } } +impl From<&LuaError> for LuneError { + fn from(value: &LuaError) -> Self { + Self { + error: value.clone(), + disable_colors: false, + } + } +} + impl Display for LuneError { fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { write!(f, "{}", self.error) // TODO: Pretty formatting diff --git a/src/lune/scheduler/impl_runner.rs b/src/lune/scheduler/impl_runner.rs index 82617cf..0ed44a8 100644 --- a/src/lune/scheduler/impl_runner.rs +++ b/src/lune/scheduler/impl_runner.rs @@ -5,6 +5,8 @@ use mlua::prelude::*; use tokio::task::LocalSet; +use crate::LuneError; + use super::Scheduler; impl<'lua, 'fut> Scheduler<'lua, 'fut> @@ -43,10 +45,10 @@ where // If we got any resumption (lua-side) error, increment // the error count of the scheduler so we can exit with // a non-zero exit code, and print it out to stderr - // TODO: Pretty print the lua error here if let Err(err) = &res { self.state.increment_error_count(); - eprint!("{err}"); + // NOTE: LuneError will pretty-format this error + eprint!("{}", LuneError::from(err)); } // Send results of resuming this thread to any listeners