slint-ui/slint · error · std::io::Error
path not found
Error message
path not found
What it means
In tools/lsp/preview.rs (around line 2201), an async closure used for loading external files checks a HashMap<PathBuf, String> of source code; if the requested PathBuf is absent it returns Some(Err(io::Error::NotFound, "path not found")) wrapped in a Result handed back to the caller. It indicates the preview's in-memory code map does not contain the requested file, so it cannot be served (with the fixed version tag Some(24) otherwise).
Solutions
- Populate the `code` map with all dependencies (full import closure) before triggering the load.
- Canonicalize paths (same separators, absolute) before inserting and looking up in the map.
- Handle the Err result by falling back to fetching the file through the normal file-system/URL path.
Example fix
// before
let Some(source) = code.get(&path) else {
return Some(Result::Err(std::io::Error::new(
std::io::ErrorKind::NotFound,
"path not found",
)));
};
// after
let canonical = path.canonicalize().unwrap_or_else(|_| path.clone());
let Some(source) = code.get(&canonical).or_else(|| code.get(&path)) else {
return Some(Result::Err(std::io::Error::new(
std::io::ErrorKind::NotFound,
format!("path not found: {}", path.display()),
)));
}; Defensive patterns
Strategy: try-catch
Validate before calling
// before invoking the async loader
if (!codeMap.has(pathKey)) {
console.warn("loader: no source for", pathKey, "— registering first");
codeMap.set(pathKey, loadFromDisk(pathKey));
} Try / catch
match loader(path).await {
Ok((version, source)) => compile_with(version, source),
Err(e) if e.kind() == std::io::ErrorKind::NotFound => compile_from_disk_fallback(path),
Err(e) => report(e),
} Prevention
- Normalize keys and lookups through the same canonicalization (Path::canonicalize or consistent separators).
- Ensure the whole import closure is inserted into the code map before compilation starts.
- Log the requested path on miss to catch casing/separator mismatches early.
When it happens
Trigger: The loader callback is invoked for a path that was never inserted into the `code` map captured by the closure — e.g. a dependency file requested before the preview populated its map, or a path with different casing/canonicalization than the keys stored.
Common situations: Live-Preview serving imported dependencies in WASM/browser context where only the main document was compiled into the map; or a path separator mismatch (Windows backslash vs URL slash) making the lookup key differ.
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
- File not registered in Live-Preview!
- {err}
- File not registered in Live-Preview!
- path not found
- Callbacks were set up earlier
AI-assisted analysis of slint-ui/slint@3a7e700487 (2026-09-16).
Data as JSON: /api/errors/6034bb0b61edaa58.
Report an issue: GitHub.
Appendix: source
Thrown at tools/lsp/preview.rs:2208
) -> ComponentInstance {
let code = Rc::new(code);
let path = main_test_file_name();
let source_code = code.get(&path).unwrap().clone();
let (diagnostics, component_definition, _, _) = spin_on::spin_on(super::parse_source(
Default::default(),
path,
Some(24),
source_code.to_string(),
style.to_string(),
None,
move |path| {
let code = code.clone();
let path = PathBuf::from(&path);
Box::pin(async move {
let Some(source) = code.get(&path) else {
return Some(Result::Err(std::io::Error::new(
std::io::ErrorKind::NotFound,
"path not found",
)));
};
Some(Ok((Some(24), source.clone())))
})
},
));
assert!(diagnostics.is_empty());
component_definition.unwrap().create().unwrap()
}
#[track_caller]
pub fn interpret_test(style: &str, source_code: &str) -> ComponentInstance {
let code = HashMap::from([(main_test_file_name(), source_code.to_string())]);
interpret_test_with_sources(style, code)View on GitHub (pinned to 3a7e700487)