diff --git a/src/types.rs b/src/types.rs index 82002f0..2d52ab0 100644 --- a/src/types.rs +++ b/src/types.rs @@ -4,14 +4,14 @@ use mlua::IntoLua; use serde::{Deserialize, Serialize}; /// Converts a `serde_json::Value` to a `mlua::Value`. -fn json_to_lua(value: serde_json::Value, lua: &mlua::Lua) -> mlua::Result> { +fn json_to_lua(value: serde_json::Value, lua: &mlua::Lua) -> mlua::Result { match value { serde_json::Value::Null => Ok(mlua::Value::Nil), serde_json::Value::Bool(value) => Ok(mlua::Value::Boolean(value)), serde_json::Value::Number(value) => match value.as_f64() { Some(number) => Ok(mlua::Value::Number(number)), None => Err(mlua::Error::ToLuaConversionError { - from: "serde_json::Value::Number", + from: String::from("serde_json::Value::Number"), to: "Number", message: Some("Number cannot be represented by a floating-point type".into()), }), @@ -52,8 +52,8 @@ pub(crate) struct ApiEvent { pub status: u16, } -impl<'lua> IntoLua<'lua> for ApiEvent { - fn into_lua(self, lua: &'lua mlua::Lua) -> mlua::Result> { +impl IntoLua for ApiEvent { + fn into_lua(self, lua: &mlua::Lua) -> mlua::Result { let headers = lua.create_table_with_capacity(0, self.headers.len())?; for (k, v) in self.headers { let k = lua.create_string(k)?; diff --git a/src/worker/lua.rs b/src/worker/lua.rs index 6ef1ad7..669c4ee 100644 --- a/src/worker/lua.rs +++ b/src/worker/lua.rs @@ -1,6 +1,6 @@ use std::sync::mpsc::Receiver; -use color_eyre::Result; +use color_eyre::{eyre, Result}; use mlua::{Function, IntoLua as _, Lua, LuaSerdeExt}; use tokio::sync::mpsc::UnboundedSender; @@ -96,23 +96,23 @@ pub fn worker( Event::Webhook(data) => { tracing::trace!(id = data.topic, "Received webhook event"); let data = lua.to_value(&data)?; - event_fn.call::<_, ()>(("webhook", data))? + event_fn.call(("webhook", data))? } Event::Api(data) => { tracing::trace!(id = data.id, status = data.status, "Received api event"); let data = data.into_lua(&lua)?; - event_fn.call::<_, ()>(("api", data))? + event_fn.call(("api", data))? } Event::Error(data) => { tracing::trace!(id = data.id, message = data.message, "Received error event"); let data = lua.to_value(&data)?; - event_fn.call::<_, ()>(("error", data))? + event_fn.call(("error", data))? } } } Ok(()) - })?; + }).map_err(|e| eyre::eyre!("{:?}", e))?; Ok(()) }