{"record":{"id":"8de269adbdc221db","repo":"tonhowtf/omniget","slug":"failed-to-emit-event","errorCode":null,"errorMessage":"Failed to emit event '{}': {}","messagePattern":"Failed to emit event '(.+?)': (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/src/plugin_host.rs","lineNumber":21,"sourceCode":"use omniget_plugin_sdk::{PluginHost, ProxyConfig};\nuse tauri::{AppHandle, Emitter, Runtime};\n\npub struct PluginHostImpl<R: Runtime> {\n    app: AppHandle<R>,\n    plugins_dir: PathBuf,\n}\n\nimpl<R: Runtime> PluginHostImpl<R> {\n    pub fn new(app: AppHandle<R>, plugins_dir: PathBuf) -> Self {\n        Self { app, plugins_dir }\n    }\n}\n\nimpl<R: Runtime + 'static> PluginHost for PluginHostImpl<R> {\n    fn emit_event(&self, name: &str, payload: serde_json::Value) -> anyhow::Result<()> {\n        self.app\n            .emit(name, payload)\n            .map_err(|e| anyhow::anyhow!(\"Failed to emit event '{}': {}\", name, e))\n    }\n\n    fn show_toast(&self, toast_type: &str, message: &str) -> anyhow::Result<()> {\n        self.app\n            .emit(\n                \"plugin-toast\",\n                serde_json::json!({\n                    \"type\": toast_type,\n                    \"message\": message,\n                }),\n            )\n            .map_err(|e| anyhow::anyhow!(\"Failed to show toast: {}\", e))\n    }\n\n    fn plugin_data_dir(&self, plugin_id: &str) -> PathBuf {\n        self.plugins_dir.join(plugin_id).join(\"data\")\n    }\n","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/src/plugin_host.rs#L3-L39","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Validate the event name against Tauri's rules (alphanumeric, '-', '/', ':', '_') before emitting.","Log and swallow emission failures for non-critical plugin events instead of propagating them.","Retry the emit if it happened during startup race; ensure the webview is initialized first.","Check the inner error message from Tauri for the actual root cause and fix accordingly."],"exampleFix":"// before\nself.app.emit(name, payload).map_err(|e| anyhow::anyhow!(\"Failed to emit event '{}': {}\", name, e))\n// after (non-critical events)\nif let Err(e) = self.app.emit(name, payload) {\n    log::warn!(\"emit '{}' failed: {e}\", name);\n}\nOk(())","handlingStrategy":"try-catch","validationCode":"fn valid_event_name(name: &str) -> bool {\n    !name.is_empty() && name.chars().all(|c| c.is_ascii_alphanumeric() || \"-/:_\".contains(c))\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = host.emit_event(\"plugin-progress\", payload) {\n    log::warn!(\"event not delivered: {e}\"); // non-fatal for plugin flow\n}","preventionTips":["Validate event names against Tauri's allowed characters before emitting","Don't emit events from plugins during app teardown/shutdown","Log emission failures instead of failing plugin execution for cosmetic events","Ensure the webview is initialized before plugin events flow"],"tags":["tauri","event-emission","plugin-host"],"backgroundTag":"http-error-response","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}