{"record":{"id":"1043f9d7bc225450","repo":"BoundaryML/baml","slug":"field-not-found-expected-expected","errorCode":null,"errorMessage":"Field not found: expected {expected}","messagePattern":"Field not found: expected (.+?)","errorType":"exception","errorClass":"AccessError","httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_heap/src/accessor.rs","lineNumber":24,"sourceCode":"\nuse baml_type::RuntimeTy;\nuse bex_external_types::{BexExternalAdt, BexExternalValue, WeakHeapRef};\nuse 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 {","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_heap/src/accessor.rs#L6-L42","documentation":"AccessError::FieldNotFound is returned when accessing a named field on a heap object that does not have it. `expected` carries the field name; the object itself was valid and of the right kind, but lacks the requested member, e.g. after a script object shape change.","triggerScenarios":"get_field(obj, \"name\") on a heap record/instance that defines no `name` field — typical after script/schema version changes or when indexing the wrong object kind.","commonSituations":"Refactored VM object layouts where a field was renamed or removed; dynamically-created objects missing optional fields; hardcoded field-name strings drifting from actual object shapes.","solutions":["Check field existence (has_field / fields list) before access and return Option instead of Err","Update the field name to match the current object layout/schema","Fix object construction to always populate the required field","Treat the error as recoverable and provide a default value at the call site"],"exampleFix":"// before\nlet v = heap.get_field(obj, \"email\")?; // field removed in new schema\n// after\nlet v = match heap.get_field(obj, \"email\") {\n    Ok(v) => v,\n    Err(AccessError::FieldNotFound { .. }) => Value::nil(),\n    Err(e) => return Err(e),\n};","handlingStrategy":"try-catch","validationCode":"if !heap.has_field(obj, \"email\") {\n    return Ok(Value::nil()); // default instead of erroring\n}","typeGuard":null,"tryCatchPattern":"match heap.get_field(obj, \"email\") {\n    Ok(v) => v,\n    Err(AccessError::FieldNotFound { expected }) => { log::debug!(\"field {expected} absent\"); Value::nil() },\n    Err(e) => return Err(e),\n}","preventionTips":["Check field existence or use Option-returning variants for optional fields","Keep field-name constants in one place, tested against object schemas","Populate all required fields at object construction"],"tags":["heap","field-access","vm"],"backgroundTag":"field-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"}