slint-ui/slint · error · std::io::Error
File not registered in Live-Preview!
Error message
File not registered in Live-Preview!
What it means
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.
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.
Defensive patterns
Strategy: fallback
Validate before calling
// caller-side check before requesting from the preview cache
// (API is internal; approximate by ensuring the document was opened/synced first)
if !opened_documents.contains(url) {
let content = std::fs::read_to_string(url.to_file_path().unwrap())?;
register_with_preview(url, content);
} Try / catch
match get_url_from_cache(&url) {
Ok((version, code)) => use_source(version, code),
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
// fall back to disk and register it
let code = std::fs::read_to_string(url.to_file_path().unwrap())?;
register_with_preview(&url, code.clone());
}
Err(e) => return Err(e),
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
AI-assisted analysis of slint-ui/slint@3a7e700487 (2026-09-16).
Data as JSON: /api/errors/11c7f766f65f79b4.
Report an issue: GitHub.
Appendix: source
Thrown at tools/lsp/preview.rs:1396
if let Some(current) = current {
load_preview(current, LoadBehavior::Reload);
}
}
/// If the file is in the cache, returns it.
///
/// If the file is not known, return a NotFound error:
/// Usually the LSP side will load the file and inform us about it soon.
/// Otherwise the file is indeed missing.
///
/// In any way, register it as a dependency
fn get_url_from_cache(url: &Url) -> std::io::Result<(SourceFileVersion, String)> {
PREVIEW_STATE.with_borrow_mut(|preview_state| {
preview_state.dependencies.insert(url.to_owned());
preview_state.source_code.get(url).map(|r| (r.version, r.code.clone())).ok_or(
std::io::Error::new(
std::io::ErrorKind::NotFound,
"File not registered in Live-Preview!",
),
)
})
}
fn get_path_from_cache(path: &Path) -> std::io::Result<(SourceFileVersion, String)> {
let url = Url::from_file_path(path).map_err(|()| {
std::io::Error::new(std::io::ErrorKind::NotFound, "Failed to convert path to URL")
})?;
get_url_from_cache(&url)
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum LoadBehavior {
/// We reload the preview, most likely because a file has changed
Reload,View on GitHub (pinned to 3a7e700487)