{"record":{"id":"f930e3730a39a02b","repo":"BoundaryML/baml","slug":"readfileref-rejected","errorCode":null,"errorMessage":"readFileRef rejected: {:?}","messagePattern":"readFileRef rejected: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-schema-wasm/src/runtime_wasm/mod.rs","lineNumber":2389,"sourceCode":"                    };\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}\n\n#[wasm_bindgen]\npub struct WasmCallContext {\n    /// Index of the orchestration graph node to use for the call","sourceCodeStart":2371,"sourceCodeEnd":2407,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-schema-wasm/src/runtime_wasm/mod.rs#L2371-L2407","documentation":"The readFileRef promise rejected with something that is not a js_sys::Error (or has no string message), so the raw Debug representation is reported: \"readFileRef rejected: {:?}\". The runtime cannot read the requested file and cannot provide a friendlier message.","triggerScenarios":"JsFuture from readFileRef resolves to Err(err) where err fails the dyn_ref::<js_sys::Error>() check or message() is not a string — e.g. rejection with a plain string, undefined, or a custom non-Error object.","commonSituations":"Custom readFileRef implementations that reject with strings (e.g. `reject('reason')`) instead of Error objects; polyfill environments where rejections are wrapped oddly.","solutions":["Inspect the Debug payload after 'readFileRef rejected:' to identify the rejection value","Make the JS readFileRef always reject with `new Error(msg)` instead of raw strings","Add a try/catch in readFileRef that converts any failure to a standard Error","Verify the underlying file access (fs/fetch) and permissions"],"exampleFix":"// before\nreject('file missing: ' + path)\n// after\nreject(new Error('file missing: ' + path))","handlingStrategy":"type-guard","validationCode":"// normalize rejections inside readFileRef so Rust always sees a js_sys::Error\nconst safeRead = async (path) => {\n  try { return await readFileRef(path); }\n  catch (e) { throw e instanceof Error ? e : new Error(String(e)); }\n};","typeGuard":"const isErrorLike = (e) => e != null && typeof e === 'object' && typeof e.message === 'string';","tryCatchPattern":"try {\n  await b.init(opts);\n} catch (e) {\n  if (String(e).startsWith('readFileRef rejected:')) {\n    console.error('readFileRef rejected with non-Error value; inspect Debug payload');\n  }\n  throw e;\n}","preventionTips":["Always reject with `new Error(...)` in readFileRef, never raw strings/undefined","Wrap third-party fs/fetch calls in readFileRef with try/catch that normalizes errors","Log rejection values in JS before they cross the WASM boundary"],"tags":["wasm","javascript","promise","file-read"],"backgroundTag":"file-read-failed","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"}