tauri-apps/tauri · error

valid plugin

Error message

valid plugin

What it means

`Builder::build` is the panicking variant of plugin construction: it calls `try_build` and `expect("valid plugin")` on the result. If the plugin builder's setup, initialization, or config deserialization returns an error, this panic fires with that underlying error message.

Solutions

  1. Switch to `try_build()` and handle the `Result` to get the real underlying error instead of a panic.
  2. Validate your plugin config section in `tauri.conf.json` against the plugin's documented config schema.
  3. Check the plugin's `setup` closure for fallible operations and return descriptive errors there.
  4. Align plugin and tauri versions (same minor version family) to avoid API drift.

Example fix

// before
let plugin = tauri::plugin::Builder::new("myplugin").build(); // panics on error
// after
let plugin = tauri::plugin::Builder::<_, serde_json::Value>::new("myplugin")
  .try_build()
  .expect("plugin config invalid — see tauri.conf.json");
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate plugin config before build
let cfg: MyPluginConfig = serde_json::from_value(
  app.config().plugins.0.get("myplugin").cloned().unwrap_or_default()
).map_err(|e| format!("bad myplugin config: {e}"))?;

Try / catch

// Use try_build instead of build
let plugin = tauri::plugin::Builder::new("myplugin")
  .try_build()
  .map_err(|e| anyhow!("plugin init failed: {e}"))?;

Prevention

When it happens

Trigger: Calling `.build()` on a `tauri::plugin::Builder` whose `setup`/`on_event`/`initialization_script` closures fail, or whose config `C` fails to deserialize from the plugin config section.

Common situations: Plugin config in `tauri.conf.json` not matching the plugin's expected config struct; plugin `setup` returning `Err` due to missing resources; third-party plugin versions incompatible with the installed tauri version.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of tauri-apps/tauri@460ec35447 (2026-09-18). Data as JSON: /api/errors/586702ff5c498a27. Report an issue: GitHub.

Appendix: source

Thrown at crates/tauri/src/plugin.rs:801

      js_init_script: self.js_init_script,
      on_navigation: self.on_navigation,
      on_page_load: self.on_page_load,
      on_window_ready: self.on_window_ready,
      on_webview_ready: self.on_webview_ready,
      on_event: self.on_event,
      on_cleanup_before_exit: self.on_cleanup_before_exit,
      on_drop: self.on_drop,
      uri_scheme_protocols: self.uri_scheme_protocols,
    })
  }

  /// Builds the [`TauriPlugin`].
  ///
  /// # Panics
  ///
  /// If the builder returns an error during [`Self::try_build`], then this method will panic.
  pub fn build(self) -> TauriPlugin<R, C> {
    self.try_build().expect("valid plugin")
  }
}

/// Plugin struct that is returned by the [`Builder`]. Should only be constructed through the builder.
pub struct TauriPlugin<R: Runtime, C: DeserializeOwned = ()> {
  name: &'static str,
  app: Option<AppHandle<R>>,
  invoke_handler: Box<InvokeHandler<R>>,
  setup: Option<Box<SetupHook<R, C>>>,
  js_init_script: Option<InitializationScript>,
  on_navigation: Box<OnNavigation<R>>,
  on_page_load: Box<OnPageLoad<R>>,
  on_window_ready: Box<OnWindowReady<R>>,
  on_webview_ready: Box<OnWebviewReady<R>>,
  on_event: Box<OnEvent<R>>,
  on_cleanup_before_exit: Box<OnCleanupBeforeExit<R>>,
  on_drop: Option<Box<OnDrop<R>>>,
  uri_scheme_protocols: HashMap<String, Arc<UriSchemeProtocol<R>>>,

View on GitHub (pinned to 460ec35447)