{"record":{"id":"21f381e31acfd729","repo":"slint-ui/slint","slug":"unexpected-empty-document","errorCode":null,"errorMessage":"Unexpected empty document","messagePattern":"Unexpected empty document","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/compiler/passes.rs","lineNumber":325,"sourceCode":"        font_collection.as_ref(),\n        diag,\n    )\n    .await;\n\n    #[cfg(feature = \"bundle-translations\")]\n    if let Some(path) = &type_loader.compiler_config.bundled_translations_path {\n        match crate::translations::TranslationsBuilder::load_translations(\n            path,\n            type_loader.compiler_config.translation_domain.as_deref().unwrap_or(\"\"),\n            &mut diag.all_loaded_files,\n        ) {\n            Ok(builder) => {\n                doc.translation_builder = Some(builder);\n            }\n            Err(err) => {\n                diag.push_error(\n                    format!(\"Cannot load bundled translation: {err}\"),\n                    doc.node.as_ref().expect(\"Unexpected empty document\"),\n                );\n            }\n        }\n    }\n\n    match type_loader.compiler_config.embed_resources {\n        #[cfg(feature = \"renderer-software\")]\n        crate::EmbedResourcesKind::EmbedTextures => {\n            let mut characters_seen = std::collections::HashSet::new();\n\n            let sf = type_loader.compiler_config.const_scale_factor.unwrap_or(1.) as f64;\n\n            // Include at least the default font sizes used in the MCU backend\n            let mut font_pixel_sizes = vec![(12. * sf) as i16];\n            use i_slint_common::sharedfontique::fontique;\n            let mut font_weights = vec![fontique::FontWeight::NORMAL.value() as u16];\n            doc.visit_all_used_components(|component| {\n                embed_glyphs::collect_font_sizes_used(component, sf, &mut font_pixel_sizes);","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/slint-ui/slint/blob/3a7e700487dc74d404cad0726378053ab763d4e0/internal/compiler/passes.rs#L307-L343","documentation":"This panic happens in `run_passes` (internal/compiler/passes.rs:324) when reporting a failure to load bundled translations. The error needs a source span, taken from `doc.node`; if the document has no AST node (`doc.node` is `None`), the `expect` panics with this message instead of producing a proper diagnostic. It only surfaces when bundled translation loading fails AND the document node is missing.","triggerScenarios":"Calling the compiler API (e.g. `compile` with `CompilerConfiguration`) where `load_bundled_translations` returns an `Err` (translation lookup fails, e.g. a broken/fluent translation resource in a custom build) on a compilation whose document node was never populated — typically an empty or pre-parse failure combined with translation loading.","commonSituations":"Custom Slint builds shipping their own bundled translations (customizing `i-slint-compiler`'s translation data); compiling empty or degenerate inputs via the interpreter/LSP; translation loading errors surfacing at the wrong stage of the pipeline.","solutions":["Fix the underlying translation-loading error: inspect the `err` inside the message ('Cannot load bundled translation: ...') for the real cause.","Ensure compilation inputs are non-empty and parseable before invoking the compiler API.","If you patched bundled translations, validate the fluent/translation resources compile and load in your build.","Report a compiler bug: the diagnostic should handle a missing document node gracefully instead of panicking."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Ensure input is non-empty and parses before full compilation\nfn ensure_valid_input(path: &std::path::Path) -> Result<(), String> {\n    let src = std::fs::read_to_string(path).map_err(|e| e.to_string())?;\n    if src.trim().is_empty() { return Err(\"document is empty\".into()); }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"// catch and surface the underlying translation error instead of the panic\nmatch compile_result {\n    Err(diags) => eprintln!(\"compilation diagnostics: {diags:?}\"),\n    Ok(c) => { /* use component */ }\n}\n// If the panic aborts the process, run compilation in a subprocess to isolate it.","preventionTips":["Never feed empty or unparsed inputs to the compiler API.","If you customize bundled translations, test that they load before shipping.","Inspect the wrapped 'Cannot load bundled translation: ...' message for the root cause."],"tags":["rust","compiler","internal-panic","translations"],"backgroundTag":"internal-invariant-violation","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"}