better errors

This commit is contained in:
Jaroslaw Konik 2025-05-26 07:00:00 +02:00
parent f211769dc4
commit 1ea7e30c63
3 changed files with 11 additions and 11 deletions

View file

@ -187,7 +187,7 @@ impl Runtime for LuaRuntime {
.expect("Error clearing entity global variable");
result
})
.map_err(|e| ScriptingError::RuntimeError(Box::new(e)))?;
.map_err(|e| ScriptingError::RuntimeError(e.to_string(), "".to_string()))?;
Ok(LuaScriptData)
}
@ -236,14 +236,14 @@ impl Runtime for LuaRuntime {
let func = engine
.globals()
.get::<_, Function>(name)
.map_err(|e| ScriptingError::RuntimeError(Box::new(e)))?;
.map_err(|e| ScriptingError::RuntimeError(e.to_string(), "".to_string()))?;
let args = args
.parse(engine)
.into_iter()
.map(|a| engine.registry_value::<mlua::Value>(&a.0).unwrap());
let result = func
.call::<_, mlua::Value>(Variadic::from_iter(args))
.map_err(|e| ScriptingError::RuntimeError(Box::new(e)))?;
.map_err(|e| ScriptingError::RuntimeError(e.to_string(), "".to_string()))?;
engine
.globals()
.set(ENTITY_VAR_NAME, mlua::Value::Nil)
@ -261,13 +261,13 @@ impl Runtime for LuaRuntime {
self.with_engine(|engine| {
let val = engine
.registry_value::<Function>(&value.0)
.map_err(|e| ScriptingError::RuntimeError(Box::new(e)))?;
.map_err(|e| ScriptingError::RuntimeError(e.to_string(), "".to_string()))?;
let args = args
.into_iter()
.map(|a| engine.registry_value::<mlua::Value>(&a.0).unwrap());
let result = val
.call::<_, mlua::Value>(Variadic::from_iter(args))
.map_err(|e| ScriptingError::RuntimeError(Box::new(e)))?;
.map_err(|e| ScriptingError::RuntimeError(e.to_string(), "".to_string()))?;
Ok(LuaValue::new(engine, result))
})
}

View file

@ -105,7 +105,7 @@ impl Runtime for RhaiRuntime {
engine
.run_ast_with_scope(&mut scope, &ast)
.map_err(|e| ScriptingError::RuntimeError(Box::new(e)))?;
.map_err(|e| ScriptingError::RuntimeError(e.to_string(), "".to_string()))?;
scope.remove::<BevyEntity>(ENTITY_VAR_NAME).unwrap();
@ -156,7 +156,7 @@ impl Runtime for RhaiRuntime {
scope.remove::<BevyEntity>(ENTITY_VAR_NAME).unwrap();
match result {
Ok(val) => Ok(RhaiValue(val)),
Err(e) => Err(ScriptingError::RuntimeError(Box::new(e))),
Err(e) => Err(ScriptingError::RuntimeError(e.to_string(), "".to_string())),
}
}
@ -173,11 +173,11 @@ impl Runtime for RhaiRuntime {
let result = if args.len() == 1 && args.first().unwrap().0.is_unit() {
f.call_raw(ctx, None, [])
.map_err(|e| ScriptingError::RuntimeError(e))?
.map_err(|e| ScriptingError::RuntimeError(e.to_string(), "".to_string()))?
} else {
let args = args.into_iter().map(|a| a.0).collect::<Vec<Dynamic>>();
f.call_raw(ctx, None, args)
.map_err(|e| ScriptingError::RuntimeError(e))?
.map_err(|e| ScriptingError::RuntimeError(e.to_string(), "".to_string()))?
};
Ok(RhaiValue(result))

View file

@ -107,7 +107,7 @@ pub(crate) fn init_callbacks<R: Runtime>(world: &mut World) -> Result<(), Script
},
);
if let Err(e) = result {
tracing::error!("error registering function: {:?}", e);
tracing::error!("error registering function: {}", e);
}
}
}
@ -158,7 +158,7 @@ pub(crate) fn process_calls<R: Runtime>(world: &mut World) -> Result<(), Scripti
match result {
Ok(_) => {}
Err(e) => {
tracing::error!("error resolving call: {} {:?}", callback.name, e);
tracing::error!("error resolving call: {} {}", callback.name, e);
}
}
}