slint-ui/slint · error · std::io::Error
path not found
Error message
path not found
What it means
In the preview's file-load callback (editor-side), the requested path is looked up in the `code` map of known sources. If the map has no entry for that `PathBuf`, the loader returns `NotFound` with the message "path not found", aborting compilation of that dependency.
Solutions
- Add the missing file's source to the `code` map before compiling, keyed by the same canonical PathBuf the loader will request
- Normalize both map keys and lookup paths (canonicalize) so they match exactly
- Verify the import path in the .slint file points to a file that exists and is registered with the preview
Example fix
// before
let Some(source) = code.get(&path) else { return Err(NotFound) };
// after
let canonical = path.canonicalize()?;
let Some(source) = code.get(&canonical) else { /* register or return NotFound */ }; Defensive patterns
Strategy: fallback
Validate before calling
if !code.contains_key(&path) {
// read the file from disk instead of the cache, or fail early with a clear message
let source = std::fs::read_to_string(&path)?;
} Type guard
fn has_cached_source(code: &HashMap<PathBuf, String>, path: &Path) -> bool {
code.contains_key(path)
} Try / catch
match code.get(&path) {
Some(source) => Ok((Some(24u32), source.clone())),
None => match std::fs::read_to_string(&path) {
Ok(src) => Ok((None, src)), // fallback to disk
Err(_) => Err(std::io::Error::new(std::io::ErrorKind::NotFound, "path not found")),
},
} Prevention
- Key the code map with canonicalized absolute paths and canonicalize the lookup path the same way
- Keep the cache in sync with file system events (create/rename/delete)
- Validate import paths against registered files before compiling
When it happens
Trigger: The compiler's file loader requests a path that is not a key in the captured `code` map — e.g. an imported .slint file whose path was never added to the map, or a path whose format differs (relative vs absolute, different separators).
Common situations: An import references a file outside the set of files the editor registered; path normalization differences (e.g. `./x.slint` vs `x.slint`) make the map lookup miss; file was deleted or moved after the map was built.
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
- Failed to convert path to URL
- File not registered in Live-Preview!
- Not an absolute file path
- File not registered in Live-Preview!
- path not found
AI-assisted analysis of slint-ui/slint@3a7e700487 (2026-09-16).
Data as JSON: /api/errors/5da9a06867592b44.
Report an issue: GitHub.
Appendix: source
Thrown at tools/editor/preview.rs:2864
) -> 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)