{"record":{"id":"2e155578681c68a3","repo":"BoundaryML/baml","slug":"function-not-found-expected","errorCode":null,"errorMessage":"Function not found: {expected}","messagePattern":"Function not found: (.+?)","errorType":"exception","errorClass":"AccessError","httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_heap/src/accessor.rs","lineNumber":27,"sourceCode":"use bex_vm_types::{HeapPtr, Object, PermitProof, Value};\n\nuse crate::BexHeap;\n\n#[derive(Debug, PartialEq, thiserror::Error, Clone)]\npub enum AccessError {\n    #[error(\"Invalid handle: expected {expected}\")]\n    InvalidHandle { expected: &'static str },\n\n    #[error(\"Type mismatch: expected {expected}, got {actual}\")]\n    TypeMismatch {\n        expected: &'static str,\n        actual: String,\n    },\n\n    #[error(\"Field not found: expected {expected}\")]\n    FieldNotFound { expected: String },\n\n    #[error(\"Function not found: {expected}\")]\n    FunctionNotFound { expected: String },\n\n    #[error(\"Cannot convert to owned: {reason}\")]\n    CannotConvertToOwned { reason: String },\n}\n\npub enum BexValue<'a> {\n    ExternalValue(&'a BexExternalValue),\n    HeapPtr(&'a HeapPtr),\n    Value(&'a Value),\n    OwnedValue(Value),\n}\n\nimpl<'a> From<&'a BexExternalValue> for BexValue<'a> {\n    fn from(value: &'a BexExternalValue) -> Self {\n        BexValue::ExternalValue(value)\n    }\n}","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_heap/src/accessor.rs#L9-L45","documentation":"AccessError::FunctionNotFound is returned when looking up a named function on the heap and no function with that name exists. `expected` is the function name; this indicates the symbol table/script context lacks the function the caller tried to resolve.","triggerScenarios":"Resolving/calling a function by name via BexHeap accessors where the name was never defined, was removed by a script reload, or is misspelled/case-mismatched.","commonSituations":"Calling into user script code that no longer defines the function after an edit; wrong module/scope for the lookup; typos in function-name constants.","solutions":["Verify the function exists (list/lookup function symbols) before invoking","Correct the function name string used at the call site","Ensure the script defining the function is loaded/registered before lookup","Handle the error gracefully (skip optional hooks) when the function may legitimately be absent"],"exampleFix":"// before\nlet f = heap.get_function(\"on_event\")?; // not defined\n// after\nmatch heap.get_function(\"on_event\") {\n    Ok(f) => call(f),\n    Err(AccessError::FunctionNotFound { expected }) => log::debug!(\"optional hook {expected} absent\"),\n    Err(e) => return Err(e),\n}","handlingStrategy":"try-catch","validationCode":"if !heap.has_function(\"on_event\") {\n    return Ok(()); // optional hook: skip silently\n}","typeGuard":null,"tryCatchPattern":"match heap.get_function(\"on_event\") {\n    Ok(f) => call(f),\n    Err(AccessError::FunctionNotFound { expected }) => { log::debug!(\"function {expected} not defined\"); skip(); },\n    Err(e) => return Err(e),\n}","preventionTips":["Verify function presence before invoking optional hooks","Centralize function-name constants and test them against loaded scripts","Ensure scripts are fully loaded/registered before VM callbacks resolve names"],"tags":["heap","function-lookup","vm"],"backgroundTag":"function-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"}