{"record":{"id":"02ffc662ac1fbd00","repo":"slint-ui/slint","slug":"cannot-set-callback-global-name-name-e","errorCode":null,"errorMessage":"Cannot set callback {global_name}::{name}: {e}","messagePattern":"Cannot set callback (.+?)::(.+?): (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/live-preview/live_component.rs","lineNumber":244,"sourceCode":"\n    /// Forward to invoke_global\n    pub fn invoke_global(&self, global_name: &str, name: &str, args: &[Value]) -> Value {\n        self.instance()\n            .invoke_global(global_name, name, args)\n            .unwrap_or_else(|e| panic!(\"Cannot invoke callback {global_name}::{name}: {e}\"))\n    }\n\n    /// Forward to set_global_callback\n    pub fn set_global_callback(\n        &self,\n        global_name: &str,\n        name: &str,\n        callback: Rc<dyn Fn(&[Value]) -> Value + 'static>,\n    ) {\n        self.callbacks.borrow_mut().insert(format!(\"{global_name}.{name}\"), callback.clone());\n        self.instance()\n            .set_global_callback(global_name, name, move |args| callback(args))\n            .unwrap_or_else(|e| panic!(\"Cannot set callback {global_name}::{name}: {e}\"));\n    }\n}\n\nenum WatcherState {\n    Starting,\n    /// The file system watcher notified the main thread of a change\n    Changed,\n    /// The main thread is waiting for the next event\n    Waiting(Waker),\n}\n\nstruct Watcher {\n    // (wouldn't need to be an option if new_cyclic() could return errors)\n    watcher: Option<FileWatcher>,\n    state: WatcherState,\n}\n\nimpl Watcher {","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/slint-ui/slint/blob/3a7e700487dc74d404cad0726378053ab763d4e0/internal/live-preview/live_component.rs#L226-L262","documentation":"LiveComponent::set_global_callback panics when the interpreter cannot install a callback on the named global singleton. The callback is cached for hot-reload replay first; a failed registration (unknown global or callback name) panics because the live preview cannot function with missing handlers.","triggerScenarios":"set_global_callback with a global_name that is not an exported global or a callback name not declared in that global.","commonSituations":"Typo in global or callback name; the callback is actually on the component root (use set_callback); globals changed during a hot-reload cycle before re-registration.","solutions":["Confirm both the global is exported and the callback is declared on that global in the .slint file","Use set_callback for callbacks declared on the component root instead","Re-register all cached callbacks after each live-reload, tolerating removed ones"],"exampleFix":"// before\nlive.set_global_callback(\"Logic\", \"on_button_clik\", |args| Value::Void); // typo\n// after\nlive.set_global_callback(\"Logic\", \"on_button_click\", |args| Value::Void);","handlingStrategy":"validation","validationCode":"fn has_global_callback(def: &slint_interpreter::ComponentDefinition, g: &str, cb: &str) -> bool {\n    def.globals().iter().any(|g2| g2.name == g) // plus property/callback inspection on that global\n}","typeGuard":null,"tryCatchPattern":"// panic! is not catchable; validate the global and callback name first\nif is_exported_global(\"Logic\") && declares_callback(\"Logic\", \"on_button_click\") {\n    live.set_global_callback(\"Logic\", \"on_button_click\", |args| Value::Void);\n}","preventionTips":["Distinguish root vs global callbacks in a thin API layer to avoid using the wrong setter","Verify exported global names in CI against the .slint sources","Re-run callback registration after every reload, skipping names that vanished"],"tags":["rust","live-preview","interpreter","panic"],"backgroundTag":"entity-not-found","analyzedSha":"3a7e700487dc74d404cad0726378053ab763d4e0","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}