{"record":{"id":"6034bb0b61edaa58","repo":"slint-ui/slint","slug":"path-not-found-preview","errorCode":null,"errorMessage":"path not found","messagePattern":"path not found","errorType":"exception","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"tools/lsp/preview.rs","lineNumber":2208,"sourceCode":"    ) -> ComponentInstance {\n        let code = Rc::new(code);\n\n        let path = main_test_file_name();\n        let source_code = code.get(&path).unwrap().clone();\n        let (diagnostics, component_definition, _, _) = spin_on::spin_on(super::parse_source(\n            Default::default(),\n            path,\n            Some(24),\n            source_code.to_string(),\n            style.to_string(),\n            None,\n            move |path| {\n                let code = code.clone();\n                let path = PathBuf::from(&path);\n\n                Box::pin(async move {\n                    let Some(source) = code.get(&path) else {\n                        return Some(Result::Err(std::io::Error::new(\n                            std::io::ErrorKind::NotFound,\n                            \"path not found\",\n                        )));\n                    };\n                    Some(Ok((Some(24), source.clone())))\n                })\n            },\n        ));\n\n        assert!(diagnostics.is_empty());\n\n        component_definition.unwrap().create().unwrap()\n    }\n\n    #[track_caller]\n    pub fn interpret_test(style: &str, source_code: &str) -> ComponentInstance {\n        let code = HashMap::from([(main_test_file_name(), source_code.to_string())]);\n        interpret_test_with_sources(style, code)","sourceCodeStart":2190,"sourceCodeEnd":2226,"githubUrl":"https://github.com/slint-ui/slint/blob/3a7e700487dc74d404cad0726378053ab763d4e0/tools/lsp/preview.rs#L2190-L2226","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nlet Some(source) = code.get(&path) else {\n    return Some(Result::Err(std::io::Error::new(\n        std::io::ErrorKind::NotFound,\n        \"path not found\",\n    )));\n};\n// after\nlet canonical = path.canonicalize().unwrap_or_else(|_| path.clone());\nlet Some(source) = code.get(&canonical).or_else(|| code.get(&path)) else {\n    return Some(Result::Err(std::io::Error::new(\n        std::io::ErrorKind::NotFound,\n        format!(\"path not found: {}\", path.display()),\n    )));\n};","handlingStrategy":"try-catch","validationCode":"// before invoking the async loader\nif (!codeMap.has(pathKey)) {\n  console.warn(\"loader: no source for\", pathKey, \"— registering first\");\n  codeMap.set(pathKey, loadFromDisk(pathKey));\n}","typeGuard":null,"tryCatchPattern":"match loader(path).await {\n    Ok((version, source)) => compile_with(version, source),\n    Err(e) if e.kind() == std::io::ErrorKind::NotFound => compile_from_disk_fallback(path),\n    Err(e) => report(e),\n}","preventionTips":["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."],"tags":["live-preview","wasm","not-found","cache"],"backgroundTag":"file-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"}