BoundaryML/baml · error · anyhow::Error

readFileRef rejected

Error message

readFileRef rejected: {:?}

What it means

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.

Solutions

  1. Inspect the Debug payload after 'readFileRef rejected:' to identify the rejection value
  2. Make the JS readFileRef always reject with `new Error(msg)` instead of raw strings
  3. Add a try/catch in readFileRef that converts any failure to a standard Error
  4. Verify the underlying file access (fs/fetch) and permissions

Example fix

// before
reject('file missing: ' + path)
// after
reject(new Error('file missing: ' + path))
Defensive patterns

Strategy: type-guard

Validate before calling

// normalize rejections inside readFileRef so Rust always sees a js_sys::Error
const safeRead = async (path) => {
  try { return await readFileRef(path); }
  catch (e) { throw e instanceof Error ? e : new Error(String(e)); }
};

Type guard

const isErrorLike = (e) => e != null && typeof e === 'object' && typeof e.message === 'string';

Try / catch

try {
  await b.init(opts);
} catch (e) {
  if (String(e).startsWith('readFileRef rejected:')) {
    console.error('readFileRef rejected with non-Error value; inspect Debug payload');
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: Custom readFileRef implementations that reject with strings (e.g. `reject('reason')`) instead of Error objects; polyfill environments where rejections are wrapped oddly.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/f930e3730a39a02b. Report an issue: GitHub.

Appendix: source

Thrown at engine/baml-schema-wasm/src/runtime_wasm/mod.rs:2389

                    };

                let null = JsValue::NULL;
                let Ok(read) = get_baml_src_cb.call1(&null, &JsValue::from(adjusted_path)) else {
                    anyhow::bail!("readFileRef did not return a promise");
                };

                let read = JsFuture::from(Promise::unchecked_from_js(read)).await;

                let read = match read {
                    Ok(read) => read,
                    Err(err) => {
                        if let Some(e) = err.dyn_ref::<js_sys::Error>() {
                            if let Some(e_str) = e.message().as_string() {
                                anyhow::bail!("readFileRef failure: {}", e_str);
                            }
                        }

                        anyhow::bail!("readFileRef rejected: {:?}", err);
                    }
                };

                // TODO: how does JsValue -> Uint8Array work without try_from?
                Ok(Uint8Array::from(read).to_vec())
            }
        })
    }))
}

#[cfg(not(target_arch = "wasm32"))]
fn js_fn_to_baml_src_reader(get_baml_src_cb: js_sys::Function) -> BamlSrcReader {
    None
}

#[wasm_bindgen]
pub struct WasmCallContext {
    /// Index of the orchestration graph node to use for the call

View on GitHub (pinned to bd85ce9dee)