Skip to content

Commit 508eddc

Browse files
authored
refactor(core): plugin initialization return value (#1575)
1 parent f708ff8 commit 508eddc

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Change plugin trait `initialization` return type to `std::result::Result<(), Box<dyn std::error::Error>>`.

core/tauri/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ pub enum Error {
5757
#[cfg(feature = "updater")]
5858
#[error("Updater: {0}")]
5959
TauriUpdater(#[from] crate::updater::Error),
60+
/// Error initializing plugin.
61+
#[error("failed to initialize plugin `{0}`: {1}")]
62+
PluginInitialization(String, String),
6063
}
6164

6265
impl From<serde_json::Error> for Error {

core/tauri/src/plugin.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ use crate::{
1212
use serde_json::Value as JsonValue;
1313
use std::collections::HashMap;
1414

15+
/// The plugin result type.
16+
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
17+
1518
/// The plugin interface.
1619
pub trait Plugin<M: Params>: Send {
1720
/// The plugin name. Used as key on the plugin config object.
1821
fn name(&self) -> &'static str;
1922

2023
/// Initialize the plugin.
2124
#[allow(unused_variables)]
22-
fn initialize(&mut self, config: JsonValue) -> crate::Result<()> {
25+
fn initialize(&mut self, config: JsonValue) -> Result<()> {
2326
Ok(())
2427
}
2528

@@ -69,7 +72,9 @@ impl<M: Params> PluginStore<M> {
6972
/// Initializes all plugins in the store.
7073
pub(crate) fn initialize(&mut self, config: &PluginConfig) -> crate::Result<()> {
7174
self.store.values_mut().try_for_each(|plugin| {
72-
plugin.initialize(config.0.get(plugin.name()).cloned().unwrap_or_default())
75+
plugin
76+
.initialize(config.0.get(plugin.name()).cloned().unwrap_or_default())
77+
.map_err(|e| crate::Error::PluginInitialization(plugin.name().to_string(), e.to_string()))
7378
})
7479
}
7580

0 commit comments

Comments
 (0)