{"record":{"id":"32046c58a6a6cf12","repo":"BoundaryML/baml","slug":"run-target-omitted-variant","errorCode":null,"errorMessage":"run target omitted variant","messagePattern":"run target omitted variant","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_events/src/value/record.rs","lineNumber":500,"sourceCode":"\nimpl From<&RunCompletedRecord> for crate::value::pb::RunCompletedV1 {\n    fn from(value: &RunCompletedRecord) -> Self {\n        Self {\n            status: run_status_to_proto(value.status) as i32,\n            completed_at_ms: value.completed_at_ms,\n            renderer_hint: value.renderer_hint.clone(),\n            result_value_ref: value.result_value_ref.as_ref().map(Into::into),\n            error: value.error.as_ref().map(run_error_to_proto),\n            cancellation: value.cancellation.as_ref().map(cancellation_to_proto),\n        }\n    }\n}\n\nfn run_target_from_proto(value: crate::value::pb::RunTargetV1) -> io::Result<RunTarget> {\n    use crate::value::pb::run_target_v1::Target;\n    match value\n        .target\n        .ok_or_else(|| io::Error::new(io::ErrorKind::InvalidData, \"run target omitted variant\"))?\n    {\n        Target::Function(target) => Ok(RunTarget::Function {\n            function_name: target.function_name,\n        }),\n        Target::Test(target) => Ok(RunTarget::Test {\n            generation: ProjectGeneration(target.generation),\n            test_name: target.test_name,\n        }),\n        Target::Preview(target) => Ok(RunTarget::Preview {\n            parent_function_name: target.parent_function_name,\n            helper: target.helper,\n        }),\n        Target::Companion(target) => {\n            let parent_boundary_id = target\n                .parent_boundary_id\n                .as_deref()\n                .map(boundary_id_from_slice)\n                .transpose()?;","sourceCodeStart":482,"sourceCodeEnd":518,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_events/src/value/record.rs#L482-L518","documentation":"run_target_from_proto converts pb::RunTargetV1 into the RunTarget domain type; it errors when the `target` oneof is None, i.e. the proto message names no concrete target variant (Function or Test). Since RunTarget is an enum with no empty case, the conversion cannot proceed and returns io::ErrorKind::InvalidData.","triggerScenarios":"Calling run_target_from_proto on a RunTargetV1 decoded without its oneof set (producer never called set_target), or a message whose variant tag was lost in transport/storage.","commonSituations":"Hand-built test messages missing the oneof; a producer/schema change where the variant field was renamed; partially written event-stream bytes.","solutions":["Populate the oneof on the producer side (set_function(...) or set_test(...))","Fix the emitter to require a concrete variant before writing the event","Reject/skip such records at decode time with a log entry","Verify producer/consumer protobuf definitions match"],"exampleFix":"// before\nlet t = run_target_from_proto(pb::RunTargetV1::default())?; // oneof unset\n// after\nlet t = run_target_from_proto(pb::RunTargetV1 {\n    target: Some(pb::run_target_v1::Target::Function(pb::FunctionTarget { function_name: \"f\".into() })),\n})?;","handlingStrategy":"validation","validationCode":"fn has_variant(v: &pb::RunTargetV1) -> bool { v.target.is_some() }","typeGuard":"fn as_target(v: pb::RunTargetV1) -> Option<pb::run_target_v1::Target> { v.target }","tryCatchPattern":"match run_target_from_proto(msg) {\n    Ok(t) => t,\n    Err(e) if e.kind() == io::ErrorKind::InvalidData => { log::warn!(\"run target oneof unset\"); RunTarget::default() },\n    Err(e) => return Err(e),\n}","preventionTips":["Construct RunTargetV1 only via helpers that require a concrete variant","Never build proto messages via Default::default() in production code","Keep producer/consumer .proto files in sync"],"tags":["protobuf","oneof","deserialization"],"backgroundTag":"invalid-enum-value","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"}