diff --git a/src-tauri/yaak_plugin_runtime/src/error.rs b/src-tauri/yaak_plugin_runtime/src/error.rs index 02def35e..32729731 100644 --- a/src-tauri/yaak_plugin_runtime/src/error.rs +++ b/src-tauri/yaak_plugin_runtime/src/error.rs @@ -17,18 +17,10 @@ pub enum Error { GrpcSendErr(#[from] SendError>), #[error("JSON error")] JsonErr(#[from] serde_json::Error), - #[error("Plugin not found error")] + #[error("Plugin not found: {0}")] PluginNotFoundErr(String), - #[error("unknown error")] - MissingCallbackIdErr(String), - #[error("Missing callback ID error")] - MissingCallbackErr(String), - #[error("No plugins found")] - NoPluginsErr(String), - #[error("Plugin error")] + #[error("Plugin error: {0}")] PluginErr(String), - #[error("Unknown error")] - UnknownErr(String), } impl Into for Error { diff --git a/src-tauri/yaak_plugin_runtime/src/manager.rs b/src-tauri/yaak_plugin_runtime/src/manager.rs index ad853e80..32ed4ec0 100644 --- a/src-tauri/yaak_plugin_runtime/src/manager.rs +++ b/src-tauri/yaak_plugin_runtime/src/manager.rs @@ -155,7 +155,7 @@ impl PluginManager { }); match result { - None => Err(PluginErr("No import responses found".to_string())), + None => Err(PluginErr("No importers found for file contents".to_string())), Some((resp, ref_id)) => { let plugin = self.server.plugin_by_ref_id(ref_id.as_str()).await?; let plugin_name = plugin.name().await; diff --git a/src-tauri/yaak_plugin_runtime/src/server.rs b/src-tauri/yaak_plugin_runtime/src/server.rs index 12736967..b2f09557 100644 --- a/src-tauri/yaak_plugin_runtime/src/server.rs +++ b/src-tauri/yaak_plugin_runtime/src/server.rs @@ -9,7 +9,7 @@ use tonic::codegen::tokio_stream::wrappers::ReceiverStream; use tonic::codegen::tokio_stream::{Stream, StreamExt}; use tonic::{Request, Response, Status, Streaming}; -use crate::error::Error::{NoPluginsErr, PluginNotFoundErr}; +use crate::error::Error::PluginNotFoundErr; use crate::error::Result; use crate::events::{BootRequest, BootResponse, InternalEvent, InternalEventPayload}; use crate::server::plugin_runtime::plugin_runtime_server::PluginRuntime; @@ -187,14 +187,11 @@ impl PluginRuntimeGrpcServer { pub async fn plugin_by_ref_id(&self, ref_id: &str) -> Result { let plugins = self.plugin_ref_to_plugin.lock().await; if plugins.is_empty() { - return Err(NoPluginsErr("Send failed because no plugins exist".into())); + return Err(PluginNotFoundErr(ref_id.into())); } match plugins.get(ref_id) { - None => { - let msg = format!("Failed to find plugin for id {ref_id}"); - Err(PluginNotFoundErr(msg)) - } + None => Err(PluginNotFoundErr(ref_id.into())), Some(p) => Ok(p.to_owned()), } } @@ -202,7 +199,7 @@ impl PluginRuntimeGrpcServer { pub async fn plugin_by_name(&self, plugin_name: &str) -> Result { let plugins = self.plugin_ref_to_plugin.lock().await; if plugins.is_empty() { - return Err(NoPluginsErr("Send failed because no plugins exist".into())); + return Err(PluginNotFoundErr(plugin_name.into())); } for p in plugins.values() { @@ -211,17 +208,20 @@ impl PluginRuntimeGrpcServer { } } - let msg = format!("Failed to find plugin for {plugin_name}"); - Err(PluginNotFoundErr(msg)) + Err(PluginNotFoundErr(plugin_name.into())) } - pub async fn send(&self, payload: &InternalEventPayload, plugin_ref_id: &str, reply_id: Option)-> Result<()> { + pub async fn send( + &self, + payload: &InternalEventPayload, + plugin_ref_id: &str, + reply_id: Option, + ) -> Result<()> { let plugin = self.plugin_by_ref_id(plugin_ref_id).await?; let event = plugin.build_event_to_send(payload, reply_id); plugin.send(&event).await } - pub async fn send_to_plugin( &self, plugin_name: &str, @@ -229,7 +229,7 @@ impl PluginRuntimeGrpcServer { ) -> Result { let plugins = self.plugin_ref_to_plugin.lock().await; if plugins.is_empty() { - return Err(NoPluginsErr("Send failed because no plugins exist".into())); + return Err(PluginNotFoundErr(plugin_name.into())); } let mut plugin = None; @@ -246,10 +246,7 @@ impl PluginRuntimeGrpcServer { plugin.send(&event).await?; Ok(event) } - None => { - let msg = format!("Failed to find plugin for {plugin_name}"); - Err(PluginNotFoundErr(msg)) - } + None => Err(PluginNotFoundErr(plugin_name.into())), } }