{"record":{"id":"01af1d07a8f98c62","repo":"slint-ui/slint","slug":"global-was-just-valid","errorCode":null,"errorMessage":"Global was just valid","messagePattern":"Global was just valid","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tools/lsp/preview/preview_data.rs","lineNumber":157,"sourceCode":"                PreviewDataKey { container: container.clone(), property_name: name },\n                PreviewData { ty, visibility, value },\n            )\n        })\n    }\n\n    let mut result = collect_preview_data(\n        PropertyContainer::Main,\n        &mut definition.properties_and_callbacks(),\n        &|name| component_instance.get_property(name).ok(),\n    )\n    .collect::<PreviewDataMap>();\n\n    for global in definition.globals() {\n        result.extend(collect_preview_data(\n            PropertyContainer::Global(global.clone()),\n            &mut definition\n                .global_properties_and_callbacks(&global)\n                .expect(\"Global was just valid\"),\n            &|name| component_instance.get_global_property(&global, name).ok(),\n        ));\n    }\n\n    result\n}\n\nfn find_component_properties_and_callbacks<'a>(\n    definition: &'a slint_interpreter::ComponentDefinition,\n    container: &PropertyContainer,\n) -> Result<\n    Box<\n        dyn Iterator<\n                Item = (\n                    String,\n                    (\n                        i_slint_compiler::langtype::Type,\n                        i_slint_compiler::object_tree::PropertyVisibility,","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/slint-ui/slint/blob/bb937076de3f7919766c1f25e2e969367cf77e9a/tools/lsp/preview/preview_data.rs#L139-L175","documentation":"Internal invariant panic from `.expect(\"Global was just valid\")` in `query_preview_data_properties_and_callbacks` (tools/lsp/preview/preview_data.rs:157). The global names being queried come from `definition.globals()` on the same `ComponentDefinition` in the same loop iteration, so `definition.global_properties_and_callbacks(&global)` is expected to always succeed (it returns None only for an unknown global). This is the live-preview path that enumerates every global's properties and callbacks for the LSP preview panel.","triggerScenarios":"Only if the interpreter's ComponentDefinition is inconsistent — i.e. `globals()` yields a name for which `global_properties_and_callbacks` returns None. In practice this would require a mismatched/slanted definition instance, a stale component_instance after recompilation, or misuse of the interpreter internals (e.g. calling this with a ComponentInstance built from a different ComponentDefinition).","commonSituations":"Developers hit this when mixing a ComponentInstance with a ComponentDefinition obtained from a different compile (e.g. after a hot reload rebuilt definitions but cached the old instance), or after interpreter API changes where globals() and global_properties_and_callbacks() no longer agree.","solutions":["Ensure the ComponentInstance and its definition() are from the same compilation; rebuild the instance whenever the definition is recompiled.","Replace the expect with graceful degradation: `if let Some(it) = definition.global_properties_and_callbacks(&global) { ... }` so preview data for one bad global doesn't panic the LSP.","Check interpreter version consistency — component_instance and definition must come from the same slint_interpreter state."],"exampleFix":"// before\n&mut definition.global_properties_and_callbacks(&global).expect(\"Global was just valid\"),\n// after\nmatch definition.global_properties_and_callbacks(&global) {\n    Some(it) => result.extend(collect_preview_data(PropertyContainer::Global(global.clone()), &mut it, &|name| component_instance.get_global_property(&global, name).ok())),\n    None => eprintln!(\"skipping inconsistent global {global}\"),\n}","handlingStrategy":"try-catch","validationCode":"// before querying, verify the global resolves on the same definition instance\nif definition.global_properties_and_callbacks(&global).is_none() {\n    eprintln!(\"global {global} missing from definition; instance/definition mismatch\");\n}","typeGuard":"fn global_is_consistent(d: &slint_interpreter::ComponentDefinition, g: &str) -> bool { d.globals().iter().any(|x| x == g) && d.global_properties_and_callbacks(g).is_some() }","tryCatchPattern":"// Rust: panics are not catchable idiomatically; replace expect with match\nmatch definition.global_properties_and_callbacks(&global) {\n    Some(it) => { /* collect preview data */ }\n    None => eprintln!(\"skipping global {global}: not found in definition\"),\n}","preventionTips":["Always pair a ComponentInstance with the definition it was created from; rebuild both on recompile.","Avoid caching ComponentDefinitions across hot-reload recompiles.","Prefer skipping bad globals over panicking in LSP/server code — one bad global should not kill the preview.","Add a test that iterates globals() and asserts global_properties_and_callbacks succeeds for each."],"tags":["rust","panic","lsp","interpreter","globals","invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bb937076de3f7919766c1f25e2e969367cf77e9a","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}