{"record":{"id":"11c7f766f65f79b4","repo":"slint-ui/slint","slug":"file-not-registered-in-live-preview-11c7f7","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/lsp/preview.rs","lineNumber":1396,"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":1378,"sourceCodeEnd":1414,"githubUrl":"https://github.com/slint-ui/slint/blob/3a7e700487dc74d404cad0726378053ab763d4e0/tools/lsp/preview.rs#L1378-L1414","documentation":"In tools/lsp/preview.rs, get_url_from_cache looks up a URL in the Live-Preview state's source_code cache after first registering it as a dependency. If the URL was never loaded into the preview (no cache entry), it returns a NotFound io::Error with \"File not registered in Live-Preview!\". This means the preview instance does not know this document — the LSP/preview handshake has not yet shared that file's contents.","triggerScenarios":"Calling get_url_from_cache (directly or via get_path_from_cache) with a Url that the preview process never received via its initial file set or subsequent update messages — e.g. fetching a dependency of a .slint file before the preview has registered that dependency's content.","commonSituations":"Opening a .slint file that imports a locally-imported dependency while Live-Preview has just (re)started and has only the main document; or a race where the LSP resolves an import before the preview state was populated.","solutions":["Ensure the file's content is sent to the preview (update the preview's source_code cache for that URL) before requesting it.","Reload/restart Live-Preview so it picks up the full dependency closure of the open document.","Handle the NotFound gracefully on the caller side by loading the file from disk and registering it in the preview cache."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// caller-side check before requesting from the preview cache\n// (API is internal; approximate by ensuring the document was opened/synced first)\nif !opened_documents.contains(url) {\n    let content = std::fs::read_to_string(url.to_file_path().unwrap())?;\n    register_with_preview(url, content);\n}","typeGuard":null,"tryCatchPattern":"match get_url_from_cache(&url) {\n    Ok((version, code)) => use_source(version, code),\n    Err(e) if e.kind() == std::io::ErrorKind::NotFound => {\n        // fall back to disk and register it\n        let code = std::fs::read_to_string(url.to_file_path().unwrap())?;\n        register_with_preview(&url, code.clone());\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always open/sync a document with Live-Preview before resolving its imports through the preview cache.","On preview restart, resend the full dependency closure instead of assuming prior state persists.","Treat NotFound as 'register and retry' rather than a hard failure in dependency lookup code."],"tags":["lsp","live-preview","cache","not-found"],"backgroundTag":"resource-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"}