{"record":{"id":"3ceaecff1d0cfdd9","repo":"slint-ui/slint","slug":"js-error-message","errorCode":null,"errorMessage":"<js error message>","messagePattern":"<js error message>","errorType":"exception","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"api/wasm-interpreter/src/lib.rs","lineNumber":95,"sourceCode":"    compiler.compiler_configuration(i_slint_core::InternalToken).is_preview = true;\n    if !style.is_empty() {\n        compiler.set_style(style)\n    }\n\n    if let Some(load_callback) = optional_import_callback {\n        let open_import_callback = move |file_name: &Path| -> core::pin::Pin<\n            Box<dyn core::future::Future<Output = Option<std::io::Result<String>>>>,\n        > {\n            Box::pin({\n                let load_callback = js_sys::Function::from(load_callback.clone());\n                let file_name: String = file_name.to_string_lossy().into();\n                async move {\n                    let result = load_callback.call1(&JsValue::UNDEFINED, &file_name.into());\n                    let promise: js_sys::Promise = result.unwrap().into();\n                    let future = wasm_bindgen_futures::JsFuture::from(promise);\n                    match future.await {\n                        Ok(js_ok) => Some(Ok(js_ok.as_string().unwrap_or_default())),\n                        Err(js_err) => Some(Err(std::io::Error::new(\n                            std::io::ErrorKind::Other,\n                            js_err.as_string().unwrap_or_default(),\n                        ))),\n                    }\n                }\n            })\n        };\n        compiler.set_file_loader(open_import_callback);\n    }\n\n    let c = compiler.build_from_source(source, base_url.into()).await;\n\n    let line_key = JsValue::from_str(\"lineNumber\");\n    let column_key = JsValue::from_str(\"columnNumber\");\n    let message_key = JsValue::from_str(\"message\");\n    let file_key = JsValue::from_str(\"fileName\");\n    let level_key = JsValue::from_str(\"level\");\n    let mut error_as_string = String::new();","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/slint-ui/slint/blob/bb937076de3f7919766c1f25e2e969367cf77e9a/api/wasm-interpreter/src/lib.rs#L77-L113","documentation":"This error surfaces a JavaScript promise rejection from a user-supplied file loader callback back into Rust as an std::io::Error. When compile_from_string_with_style encounters an import that the JS `load_callback` must fetch asynchronously, a rejected promise means the file could not be loaded (e.g. network failure, 404, or JS exception). The rejected JsValue's string message becomes the io::Error's message and is propagated to the caller of the Slint WASM compiler API.","triggerScenarios":"Calling compile_from_string (via the wasm-interpreter API) on .slint source that imports other files, where the registered JS file loader returns a rejected Promise, throws inside the async loader, or resolves to a non-string value (as_string().unwrap_or_default() yields an empty message).","commonSituations":"Web apps loading .slint files over HTTP with fetch-based loaders that hit 404s, CORS rejections, or offline conditions; loader code throwing TypeErrors; passing a loader that resolves with a Blob/arraybuffer instead of a string.","solutions":["Inspect the error message; it is the stringified JS rejection reason — fix the underlying loader failure (wrong URL, 404, CORS).","Verify the JS file loader always returns a Promise<string> of file contents for every requested path.","Add try/catch or .catch() around fetch logic in the loader and return a descriptive error message.","Ensure imported files exist on the server or are embedded/inlined so the loader is never called for missing assets."],"exampleFix":"// before\nload: (name) => fetch('/ui/' + name).then(r => r.text())\n// after\nload: (name) => fetch('/ui/' + name).then(r => {\n  if (!r.ok) throw new Error(`failed to load ${name}: HTTP ${r.status}`);\n  return r.text();\n}).catch(e => { throw new Error('slint file loader: ' + e.message); })","handlingStrategy":"try-catch","validationCode":"// JS: verify the loader resolves every path with a string\nconst res = await load_callback('App.slint');\nif (typeof res !== 'string') throw new Error('loader must return a string');","typeGuard":"function isLoaderResult(v) { return v instanceof Promise; }","tryCatchPattern":"try { await instance.compile(source, style); } catch (e) { console.error('slint load failed:', e.message); }","preventionTips":["Always return Promise<string> from the file loader; wrap non-string results with .then(String).","Add .catch() to fetch calls to convert network/CORS failures into descriptive messages.","Pre-check imported file URLs with HEAD requests or a bundled manifest."],"tags":["wasm","javascript","file-loading","async"],"backgroundTag":"file-read-failed","analyzedSha":"bb937076de3f7919766c1f25e2e969367cf77e9a","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}