{"record":{"id":"4654f57d77ad061e","repo":"BoundaryML/baml","slug":"readfileref-failure","errorCode":null,"errorMessage":"readFileRef failure: {}","messagePattern":"readFileRef failure: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-schema-wasm/src/runtime_wasm/mod.rs","lineNumber":2385,"sourceCode":"                            is_windows,\n                            path.starts_with(\"../\") || path.starts_with(\"./\")\n                        )));\n                        path.clone()\n                    };\n\n                let null = JsValue::NULL;\n                let Ok(read) = get_baml_src_cb.call1(&null, &JsValue::from(adjusted_path)) else {\n                    anyhow::bail!(\"readFileRef did not return a promise\");\n                };\n\n                let read = JsFuture::from(Promise::unchecked_from_js(read)).await;\n\n                let read = match read {\n                    Ok(read) => read,\n                    Err(err) => {\n                        if let Some(e) = err.dyn_ref::<js_sys::Error>() {\n                            if let Some(e_str) = e.message().as_string() {\n                                anyhow::bail!(\"readFileRef failure: {}\", e_str);\n                            }\n                        }\n\n                        anyhow::bail!(\"readFileRef rejected: {:?}\", err);\n                    }\n                };\n\n                // TODO: how does JsValue -> Uint8Array work without try_from?\n                Ok(Uint8Array::from(read).to_vec())\n            }\n        })\n    }))\n}\n\n#[cfg(not(target_arch = \"wasm32\"))]\nfn js_fn_to_baml_src_reader(get_baml_src_cb: js_sys::Function) -> BamlSrcReader {\n    None\n}","sourceCodeStart":2367,"sourceCodeEnd":2403,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-schema-wasm/src/runtime_wasm/mod.rs#L2367-L2403","documentation":"The Promise returned by readFileRef rejected, and the rejection was a js_sys::Error whose message is surfaced as \"readFileRef failure: {message}\". This is the file-read implementation on the JS side failing for the requested BAML source path.","triggerScenarios":"JsFuture from the readFileRef promise resolves to Err(err); err.dyn_ref::<js_sys::Error>() succeeds and its .message() converts to a string, e.g. ENOENT from Node fs, permission errors, or browser fetch failures.","commonSituations":"BAML source path doesn't exist in the deployed bundle (missing .baml files in the build output), wrong root directory configured, or Node fs error like EACCES/EISDIR surfacing through the callback.","solutions":["Read the embedded JS error message (e.g. ENOENT path) and fix the underlying file issue","Ensure .baml source files are included in the deployment/bundle output","Correct the baml_src root path passed to BAML initialization","Test readFileRef directly in JS with the failing path"],"exampleFix":"// before\nb.init({}) // relies on default path\n// after\nb.init({\n  bamlSrc: './baml_src',\n  readFileRef: async (path) => fs.promises.readFile(path),\n})","handlingStrategy":"try-catch","validationCode":"// verify the file is readable through the same callback before BAML uses it\ntry { await readFileRef('baml_src/main.baml'); } catch (e) { throw new Error(`baml source unreadable: ${e.message}`); }","typeGuard":"const isJsError = (e) => e instanceof Error && typeof e.message === 'string';","tryCatchPattern":"try {\n  await b.test.run(name);\n} catch (e) {\n  const m = String(e);\n  if (m.includes('readFileRef failure:')) {\n    if (m.includes('ENOENT')) console.error('baml file missing from bundle');\n    if (m.includes('EACCES')) console.error('permission denied on baml file');\n  }\n  throw e;\n}","preventionTips":["Ensure .baml files are copied into build/deploy output (check bundler asset rules)","Use absolute, resolved paths for baml_src in serverless environments","Pre-verify file accessibility in a startup health check"],"tags":["wasm","javascript","file-read","promise"],"backgroundTag":"file-not-found","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}