slint-ui/slint · error
Global was just valid
Error message
Global was just valid
What it means
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.
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.
Example fix
// before
&mut definition.global_properties_and_callbacks(&global).expect("Global was just valid"),
// after
match definition.global_properties_and_callbacks(&global) {
Some(it) => result.extend(collect_preview_data(PropertyContainer::Global(global.clone()), &mut it, &|name| component_instance.get_global_property(&global, name).ok())),
None => eprintln!("skipping inconsistent global {global}"),
} Defensive patterns
Strategy: try-catch
Validate before calling
// before querying, verify the global resolves on the same definition instance
if definition.global_properties_and_callbacks(&global).is_none() {
eprintln!("global {global} missing from definition; instance/definition mismatch");
} Type guard
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() } Try / catch
// Rust: panics are not catchable idiomatically; replace expect with match
match definition.global_properties_and_callbacks(&global) {
Some(it) => { /* collect preview data */ }
None => eprintln!("skipping global {global}: not found in definition"),
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
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 slint-ui/slint@bb937076de (2026-09-16).
Data as JSON: /api/errors/01af1d07a8f98c62.
Report an issue: GitHub.
Appendix: source
Thrown at tools/lsp/preview/preview_data.rs:157
PreviewDataKey { container: container.clone(), property_name: name },
PreviewData { ty, visibility, value },
)
})
}
let mut result = collect_preview_data(
PropertyContainer::Main,
&mut definition.properties_and_callbacks(),
&|name| component_instance.get_property(name).ok(),
)
.collect::<PreviewDataMap>();
for global in definition.globals() {
result.extend(collect_preview_data(
PropertyContainer::Global(global.clone()),
&mut definition
.global_properties_and_callbacks(&global)
.expect("Global was just valid"),
&|name| component_instance.get_global_property(&global, name).ok(),
));
}
result
}
fn find_component_properties_and_callbacks<'a>(
definition: &'a slint_interpreter::ComponentDefinition,
container: &PropertyContainer,
) -> Result<
Box<
dyn Iterator<
Item = (
String,
(
i_slint_compiler::langtype::Type,
i_slint_compiler::object_tree::PropertyVisibility,View on GitHub (pinned to bb937076de)