Pretty-print lua errors

This commit is contained in:
Filip Tibell 2023-08-19 17:15:24 -05:00
parent 4acc730d38
commit b69f824b57
2 changed files with 13 additions and 2 deletions

View file

@ -62,6 +62,15 @@ impl From<LuaError> 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

View file

@ -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