slint-ui/slint · error · std::io::Error
File not registered in Live-Preview!
Error message
File not registered in Live-Preview!
What it means
`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.
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
Example fix
// before
let (version, code) = get_url_from_cache(&url)?; // NotFound if unregistered
// after: register first or handle absence
if !is_registered(&url) { register_file(&url, source)?; }
let (version, code) = get_url_from_cache(&url)?; Defensive patterns
Strategy: try-catch
Validate before calling
let registered = PREVIEW_STATE.with_borrow(|s| s.source_code.get(url).is_some());
if !registered {
// register the file or report a friendly 'file not open in preview' error first
} Type guard
fn is_registered(url: &Url) -> bool {
PREVIEW_STATE.with_borrow(|s| s.source_code.contains_key(url))
} Try / catch
match get_url_from_cache(&url) {
Ok((version, code)) => { /* proceed */ }
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
// fall back: read from disk or prompt the editor to register the file
}
Err(e) => return Err(e),
} Prevention
- 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
When it happens
Trigger: `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.
Common situations: 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.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
AI-assisted analysis of slint-ui/slint@3a7e700487 (2026-09-16).
Data as JSON: /api/errors/2fa754c30967d74d.
Report an issue: GitHub.
Appendix: source
Thrown at tools/editor/preview.rs:2031
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)