diff --git a/.changes/plugin-initialization-result.md b/.changes/plugin-initialization-result.md new file mode 100644 index 000000000..8ed9e6034 --- /dev/null +++ b/.changes/plugin-initialization-result.md @@ -0,0 +1,5 @@ +--- +"tauri": patch +--- + +Change plugin trait `initialization` return type to `std::result::Result<(), Box>`. diff --git a/core/tauri/src/error.rs b/core/tauri/src/error.rs index 6e4666673..7505e58d2 100644 --- a/core/tauri/src/error.rs +++ b/core/tauri/src/error.rs @@ -57,6 +57,9 @@ pub enum Error { #[cfg(feature = "updater")] #[error("Updater: {0}")] TauriUpdater(#[from] crate::updater::Error), + /// Error initializing plugin. + #[error("failed to initialize plugin `{0}`: {1}")] + PluginInitialization(String, String), } impl From for Error { diff --git a/core/tauri/src/plugin.rs b/core/tauri/src/plugin.rs index be0bba8b3..dda999fd4 100644 --- a/core/tauri/src/plugin.rs +++ b/core/tauri/src/plugin.rs @@ -12,6 +12,9 @@ use crate::{ use serde_json::Value as JsonValue; use std::collections::HashMap; +/// The plugin result type. +pub type Result = std::result::Result>; + /// The plugin interface. pub trait Plugin: Send { /// The plugin name. Used as key on the plugin config object. @@ -19,7 +22,7 @@ pub trait Plugin: Send { /// Initialize the plugin. #[allow(unused_variables)] - fn initialize(&mut self, config: JsonValue) -> crate::Result<()> { + fn initialize(&mut self, config: JsonValue) -> Result<()> { Ok(()) } @@ -69,7 +72,9 @@ impl PluginStore { /// Initializes all plugins in the store. pub(crate) fn initialize(&mut self, config: &PluginConfig) -> crate::Result<()> { self.store.values_mut().try_for_each(|plugin| { - plugin.initialize(config.0.get(plugin.name()).cloned().unwrap_or_default()) + plugin + .initialize(config.0.get(plugin.name()).cloned().unwrap_or_default()) + .map_err(|e| crate::Error::PluginInitialization(plugin.name().to_string(), e.to_string())) }) }