{"record":{"id":"2fa754c30967d74d","repo":"slint-ui/slint","slug":"file-not-registered-in-live-preview","errorCode":null,"errorMessage":"File not registered in Live-Preview!","messagePattern":"File not registered in Live-Preview!","errorType":"exception","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"tools/editor/preview.rs","lineNumber":2031,"sourceCode":"\n    if let Some(current) = current {\n        load_preview(current, LoadBehavior::Reload);\n    }\n}\n\n/// If the file is in the cache, returns it.\n///\n/// If the file is not known, return a NotFound error:\n/// Usually the LSP side will load the file and inform us about it soon.\n/// Otherwise the file is indeed missing.\n///\n/// In any way, register it as a dependency\nfn get_url_from_cache(url: &Url) -> std::io::Result<(SourceFileVersion, String)> {\n    PREVIEW_STATE.with_borrow_mut(|preview_state| {\n        preview_state.dependencies.insert(url.to_owned());\n\n        preview_state.source_code.get(url).map(|r| (r.version, r.code.clone())).ok_or(\n            std::io::Error::new(\n                std::io::ErrorKind::NotFound,\n                \"File not registered in Live-Preview!\",\n            ),\n        )\n    })\n}\n\nfn get_path_from_cache(path: &Path) -> std::io::Result<(SourceFileVersion, String)> {\n    let url = Url::from_file_path(path).map_err(|()| {\n        std::io::Error::new(std::io::ErrorKind::NotFound, \"Failed to convert path to URL\")\n    })?;\n    get_url_from_cache(&url)\n}\n\n#[derive(Copy, Clone, Debug, PartialEq, Eq)]\npub enum LoadBehavior {\n    /// We reload the preview, most likely because a file has changed\n    Reload,","sourceCodeStart":2013,"sourceCodeEnd":2049,"githubUrl":"https://github.com/slint-ui/slint/blob/3a7e700487dc74d404cad0726378053ab763d4e0/tools/editor/preview.rs#L2013-L2049","documentation":"`get_url_from_cache` looks up a dependency URL in the live-preview editor's registered source code map. The URL was recorded as a dependency, but no source content was ever registered for it, so the lookup fails with `NotFound`. This guards against compiling a file the preview has never received from the editor.","triggerScenarios":"`get_url_from_cache(&url)` is called (e.g. by `get_path_from_cache` or the file loader) for a URL that was never inserted into `preview_state.source_code` — e.g. an import of a file the editor never opened or pushed to the preview state.","commonSituations":"Importing a .slint file that isn't open/registered in the editor's preview state; a stale dependency after renaming/moving a file; preview started before dependency files were loaded.","solutions":["Ensure the imported file is opened/registered in the live-preview state before compiling (check how PREVIEW_STATE.source_code is populated)","Reload/restart the live preview so the dependency set and source cache are rebuilt","Verify the URL matches exactly (scheme, host, path) what was registered — a canonicalization mismatch makes lookups miss"],"exampleFix":"// before\nlet (version, code) = get_url_from_cache(&url)?; // NotFound if unregistered\n// after: register first or handle absence\nif !is_registered(&url) { register_file(&url, source)?; }\nlet (version, code) = get_url_from_cache(&url)?;","handlingStrategy":"try-catch","validationCode":"let registered = PREVIEW_STATE.with_borrow(|s| s.source_code.get(url).is_some());\nif !registered {\n    // register the file or report a friendly 'file not open in preview' error first\n}","typeGuard":"fn is_registered(url: &Url) -> bool {\n    PREVIEW_STATE.with_borrow(|s| s.source_code.contains_key(url))\n}","tryCatchPattern":"match get_url_from_cache(&url) {\n    Ok((version, code)) => { /* proceed */ }\n    Err(e) if e.kind() == std::io::ErrorKind::NotFound => {\n        // fall back: read from disk or prompt the editor to register the file\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Register every imported file in PREVIEW_STATE.source_code before triggering a compile","Compare URLs after normalization (Url::from_file_path on canonicalized paths) to avoid key mismatches","Rebuild the dependency cache on file rename/move events"],"tags":["io","cache","live-preview","lsp"],"backgroundTag":"file-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"}