tonhowtf/omniget · error

Failed to emit event

Error message

Failed to emit event '{}': {}

What it means

PluginHostImpl::emit_event forwards plugin events to the Tauri webview via app.emit(name, payload). Tauri's emit can fail (serialization of listeners/registers or runtime channel issues); this wraps that failure in an anyhow error carrying the event name and the underlying message. The plugin's event simply does not reach the frontend.

Solutions

  1. Validate the event name against Tauri's rules (alphanumeric, '-', '/', ':', '_') before emitting.
  2. Log and swallow emission failures for non-critical plugin events instead of propagating them.
  3. Retry the emit if it happened during startup race; ensure the webview is initialized first.
  4. Check the inner error message from Tauri for the actual root cause and fix accordingly.

Example fix

// before
self.app.emit(name, payload).map_err(|e| anyhow::anyhow!("Failed to emit event '{}': {}", name, e))
// after (non-critical events)
if let Err(e) = self.app.emit(name, payload) {
    log::warn!("emit '{}' failed: {e}", name);
}
Ok(())
Defensive patterns

Strategy: try-catch

Validate before calling

fn valid_event_name(name: &str) -> bool {
    !name.is_empty() && name.chars().all(|c| c.is_ascii_alphanumeric() || "-/:_".contains(c))
}

Try / catch

if let Err(e) = host.emit_event("plugin-progress", payload) {
    log::warn!("event not delivered: {e}"); // non-fatal for plugin flow
}

Prevention

When it happens

Trigger: Calling emit_event with an event name the Tauri runtime refuses (e.g. reserved/invalid name), or when the app runtime's event system is shutting down / the webview window is gone while a plugin emits an event.

Common situations: Plugin emits during app teardown; a typo'd or malformed event name; emitting from a background thread after the window was closed; Tauri runtime version where certain characters in event names are rejected.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/8de269adbdc221db. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/src/plugin_host.rs:21

use omniget_plugin_sdk::{PluginHost, ProxyConfig};
use tauri::{AppHandle, Emitter, Runtime};

pub struct PluginHostImpl<R: Runtime> {
    app: AppHandle<R>,
    plugins_dir: PathBuf,
}

impl<R: Runtime> PluginHostImpl<R> {
    pub fn new(app: AppHandle<R>, plugins_dir: PathBuf) -> Self {
        Self { app, plugins_dir }
    }
}

impl<R: Runtime + 'static> PluginHost for PluginHostImpl<R> {
    fn emit_event(&self, name: &str, payload: serde_json::Value) -> anyhow::Result<()> {
        self.app
            .emit(name, payload)
            .map_err(|e| anyhow::anyhow!("Failed to emit event '{}': {}", name, e))
    }

    fn show_toast(&self, toast_type: &str, message: &str) -> anyhow::Result<()> {
        self.app
            .emit(
                "plugin-toast",
                serde_json::json!({
                    "type": toast_type,
                    "message": message,
                }),
            )
            .map_err(|e| anyhow::anyhow!("Failed to show toast: {}", e))
    }

    fn plugin_data_dir(&self, plugin_id: &str) -> PathBuf {
        self.plugins_dir.join(plugin_id).join("data")
    }

View on GitHub (pinned to 8600b91f42)