mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-22 08:48:26 +02:00
Surface plugin error on import
This commit is contained in:
@@ -17,18 +17,10 @@ pub enum Error {
|
|||||||
GrpcSendErr(#[from] SendError<tonic::Result<EventStreamEvent>>),
|
GrpcSendErr(#[from] SendError<tonic::Result<EventStreamEvent>>),
|
||||||
#[error("JSON error")]
|
#[error("JSON error")]
|
||||||
JsonErr(#[from] serde_json::Error),
|
JsonErr(#[from] serde_json::Error),
|
||||||
#[error("Plugin not found error")]
|
#[error("Plugin not found: {0}")]
|
||||||
PluginNotFoundErr(String),
|
PluginNotFoundErr(String),
|
||||||
#[error("unknown error")]
|
#[error("Plugin error: {0}")]
|
||||||
MissingCallbackIdErr(String),
|
|
||||||
#[error("Missing callback ID error")]
|
|
||||||
MissingCallbackErr(String),
|
|
||||||
#[error("No plugins found")]
|
|
||||||
NoPluginsErr(String),
|
|
||||||
#[error("Plugin error")]
|
|
||||||
PluginErr(String),
|
PluginErr(String),
|
||||||
#[error("Unknown error")]
|
|
||||||
UnknownErr(String),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<String> for Error {
|
impl Into<String> for Error {
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ impl PluginManager {
|
|||||||
});
|
});
|
||||||
|
|
||||||
match result {
|
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)) => {
|
Some((resp, ref_id)) => {
|
||||||
let plugin = self.server.plugin_by_ref_id(ref_id.as_str()).await?;
|
let plugin = self.server.plugin_by_ref_id(ref_id.as_str()).await?;
|
||||||
let plugin_name = plugin.name().await;
|
let plugin_name = plugin.name().await;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use tonic::codegen::tokio_stream::wrappers::ReceiverStream;
|
|||||||
use tonic::codegen::tokio_stream::{Stream, StreamExt};
|
use tonic::codegen::tokio_stream::{Stream, StreamExt};
|
||||||
use tonic::{Request, Response, Status, Streaming};
|
use tonic::{Request, Response, Status, Streaming};
|
||||||
|
|
||||||
use crate::error::Error::{NoPluginsErr, PluginNotFoundErr};
|
use crate::error::Error::PluginNotFoundErr;
|
||||||
use crate::error::Result;
|
use crate::error::Result;
|
||||||
use crate::events::{BootRequest, BootResponse, InternalEvent, InternalEventPayload};
|
use crate::events::{BootRequest, BootResponse, InternalEvent, InternalEventPayload};
|
||||||
use crate::server::plugin_runtime::plugin_runtime_server::PluginRuntime;
|
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<PluginHandle> {
|
pub async fn plugin_by_ref_id(&self, ref_id: &str) -> Result<PluginHandle> {
|
||||||
let plugins = self.plugin_ref_to_plugin.lock().await;
|
let plugins = self.plugin_ref_to_plugin.lock().await;
|
||||||
if plugins.is_empty() {
|
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) {
|
match plugins.get(ref_id) {
|
||||||
None => {
|
None => Err(PluginNotFoundErr(ref_id.into())),
|
||||||
let msg = format!("Failed to find plugin for id {ref_id}");
|
|
||||||
Err(PluginNotFoundErr(msg))
|
|
||||||
}
|
|
||||||
Some(p) => Ok(p.to_owned()),
|
Some(p) => Ok(p.to_owned()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -202,7 +199,7 @@ impl PluginRuntimeGrpcServer {
|
|||||||
pub async fn plugin_by_name(&self, plugin_name: &str) -> Result<PluginHandle> {
|
pub async fn plugin_by_name(&self, plugin_name: &str) -> Result<PluginHandle> {
|
||||||
let plugins = self.plugin_ref_to_plugin.lock().await;
|
let plugins = self.plugin_ref_to_plugin.lock().await;
|
||||||
if plugins.is_empty() {
|
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() {
|
for p in plugins.values() {
|
||||||
@@ -211,17 +208,20 @@ impl PluginRuntimeGrpcServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let msg = format!("Failed to find plugin for {plugin_name}");
|
Err(PluginNotFoundErr(plugin_name.into()))
|
||||||
Err(PluginNotFoundErr(msg))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send(&self, payload: &InternalEventPayload, plugin_ref_id: &str, reply_id: Option<String>)-> Result<()> {
|
pub async fn send(
|
||||||
|
&self,
|
||||||
|
payload: &InternalEventPayload,
|
||||||
|
plugin_ref_id: &str,
|
||||||
|
reply_id: Option<String>,
|
||||||
|
) -> Result<()> {
|
||||||
let plugin = self.plugin_by_ref_id(plugin_ref_id).await?;
|
let plugin = self.plugin_by_ref_id(plugin_ref_id).await?;
|
||||||
let event = plugin.build_event_to_send(payload, reply_id);
|
let event = plugin.build_event_to_send(payload, reply_id);
|
||||||
plugin.send(&event).await
|
plugin.send(&event).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub async fn send_to_plugin(
|
pub async fn send_to_plugin(
|
||||||
&self,
|
&self,
|
||||||
plugin_name: &str,
|
plugin_name: &str,
|
||||||
@@ -229,7 +229,7 @@ impl PluginRuntimeGrpcServer {
|
|||||||
) -> Result<InternalEvent> {
|
) -> Result<InternalEvent> {
|
||||||
let plugins = self.plugin_ref_to_plugin.lock().await;
|
let plugins = self.plugin_ref_to_plugin.lock().await;
|
||||||
if plugins.is_empty() {
|
if plugins.is_empty() {
|
||||||
return Err(NoPluginsErr("Send failed because no plugins exist".into()));
|
return Err(PluginNotFoundErr(plugin_name.into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut plugin = None;
|
let mut plugin = None;
|
||||||
@@ -246,10 +246,7 @@ impl PluginRuntimeGrpcServer {
|
|||||||
plugin.send(&event).await?;
|
plugin.send(&event).await?;
|
||||||
Ok(event)
|
Ok(event)
|
||||||
}
|
}
|
||||||
None => {
|
None => Err(PluginNotFoundErr(plugin_name.into())),
|
||||||
let msg = format!("Failed to find plugin for {plugin_name}");
|
|
||||||
Err(PluginNotFoundErr(msg))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user