{"record":{"id":"4e21810f1400d682","repo":"BoundaryML/baml","slug":"value-record-omitted-metadata","errorCode":null,"errorMessage":"value record omitted metadata","messagePattern":"value record omitted metadata","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_events/src/value/read.rs","lineNumber":93,"sourceCode":"        ));\n    }\n    if let Some(started) = record.run_started {\n        return Ok(ValueFileRecord::RunStarted(started.try_into()?));\n    }\n    if let Some(completed) = record.run_completed {\n        return Ok(ValueFileRecord::RunCompleted(completed.try_into()?));\n    }\n    if let Some(loss) = record.capture_loss {\n        if record.metadata.is_some() || has_log_event {\n            return Err(io::Error::new(\n                io::ErrorKind::InvalidData,\n                \"value record mixed capture loss metadata with body metadata\",\n            ));\n        }\n        return Ok(ValueFileRecord::CaptureLoss(loss.try_into()?));\n    }\n    let metadata = record.metadata.ok_or_else(|| {\n        io::Error::new(io::ErrorKind::InvalidData, \"value record omitted metadata\")\n    })?;\n    if let Some(log_event) = record.log_event {\n        return Ok(ValueFileRecord::LogEvent(LogRecord {\n            value_ref: metadata.try_into()?,\n            body: record.body,\n            blob_ref: record.blob.map(TryInto::try_into).transpose()?,\n            event: log_event.try_into()?,\n        }));\n    }\n    Err(io::Error::new(\n        io::ErrorKind::InvalidData,\n        \"body record omitted log metadata\",\n    ))\n}\n\n#[cfg(test)]\nmod tests {\n    use prost::Message as _;","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_events/src/value/read.rs#L75-L111","documentation":"After lifecycle and capture_loss checks, every remaining value-file record must include metadata; file_record_from_proto fails with this error when record.metadata is None. Metadata carries the value_ref and trace context, so a body or log event without it cannot be attributed. Raised as io::Error(InvalidData) during read_bamlvalue_from_bytes.","triggerScenarios":"Decoding a record that has no lifecycle oneof, no capture_loss, and no metadata — e.g. a truncated write that zeroed the metadata field, or a writer that emitted a body without metadata.","commonSituations":"Truncated/corrupted files from a crash mid-write, hand-crafted records in tests or tools, or buggy custom writers omitting the metadata field for log events.","solutions":["Regenerate the value file; a record missing metadata is unattributable and should be treated as corrupt.","Fix the writer so every LogEvent/body record includes the metadata (value_ref) field.","Check for interrupted writes — enable atomic/whole-record writes or detect truncation before reading."],"exampleFix":"// before\nlet record = ValueFileRecordProto { body, ..Default::default() }; // metadata omitted\n// after\nlet record = ValueFileRecordProto { metadata: Some(meta_proto), body, ..Default::default() };","handlingStrategy":"validation","validationCode":"if record.metadata.is_none() && record.run_started.is_none()\n    && record.run_completed.is_none() && record.capture_loss.is_none() {\n    // record is missing metadata; do not write it\n}","typeGuard":null,"tryCatchPattern":"let value = read_bamlvalue_from_bytes(&bytes).map_err(|e| {\n    if e.to_string().contains(\"omitted metadata\") {\n        eprintln!(\"record missing value_ref metadata — file likely truncated: {e}\");\n    }\n    e\n})?;","preventionTips":["Always populate metadata (with value_ref) on log-event/body records.","Use atomic whole-record writes so a crash cannot produce a metadata-less record.","Detect truncation by checking for a final run_completed record before trusting the file."],"tags":["rust","event-file","protobuf","corruption"],"backgroundTag":"missing-required-argument","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}