{"record":{"id":"3426a7f2d3c5b544","repo":"BoundaryML/baml","slug":"failed-to-distribute-type-with-meta-0","errorCode":null,"errorMessage":"Failed to distribute_type_with_meta: {0}","messagePattern":"Failed to distribute_type_with_meta: (.+?)","errorType":"exception","errorClass":"StreamingError","httpStatus":null,"severity":"error","filePath":"engine/baml-lib/jsonish/src/deserializer/semantic_streaming.rs","lineNumber":28,"sourceCode":"use indexmap::{IndexMap, IndexSet};\nuse internal_baml_core::ir::{\n    ir_helpers::infer_type_with_meta,\n    repr::{IntermediateRepr, Walker},\n    Field, IRHelper, IRHelperExtended, IRSemanticStreamingHelper,\n};\nuse thiserror;\n\nuse crate::{deserializer::coercer::ParsingError, BamlValueWithFlags, Flag};\n\n#[derive(Debug, thiserror::Error)]\npub enum StreamingError {\n    #[error(\"Expected to encounter a class\")]\n    ExpectedClass,\n    #[error(\"Value was marked Done, but was incomplete in the stream\")]\n    IncompleteDoneValue,\n    #[error(\"Class instance did not contain fields marked as needed: {fields:?}\")]\n    MissingNeededFields { fields: Vec<String> },\n    #[error(\"Failed to distribute_type_with_meta: {0}\")]\n    DistributeTypeWithMetaFailure(#[from] anyhow::Error),\n}\n\n/// For a given baml value, traverse its nodes, comparing the completion state\n/// of each node against the streaming behavior of the node's type.\npub fn validate_streaming_state(\n    ir: &impl IRHelperExtended,\n    baml_value: &BamlValueWithFlags,\n    mode: baml_types::StreamingMode,\n) -> Result<BamlValueWithMeta<Completion>, StreamingError> {\n    let baml_value_with_meta_flags: BamlValueWithMeta<Vec<Flag>> = baml_value.clone().into();\n    let typed_baml_value: BamlValueWithMeta<(Vec<Flag>, TypeIR)> =\n        ir.distribute_type_with_meta(baml_value_with_meta_flags, baml_value.field_type().clone())?;\n    let baml_value_with_streaming_state_and_behavior =\n        typed_baml_value.map_meta(|(flags, r#type)| (completion_state(flags), r#type));\n\n    let top_level_node = process_node(\n        ir,","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/jsonish/src/deserializer/semantic_streaming.rs#L10-L46","documentation":"StreamingError::DistributeTypeWithMetaFailure wraps an anyhow error from distribute_type_with_meta via #[from]. Type distribution (choosing/propagating the concrete type with its metadata across the streamed value) failed for an underlying reason such as an unknown enum/class or unresolvable alias.","triggerScenarios":"Any failure inside distribute_type_with_meta during streaming deserialization — typically because a referenced type (enum, class, alias) could not be resolved against the output format while distributing types over streamed nodes.","commonSituations":"Schema/client mismatch where generated code references types absent from the runtime output format; recursive alias resolution failing mid-stream; stale partial caches referencing removed types.","solutions":["Read the inner anyhow message (source of this error) to identify which type failed to distribute.","Regenerate the BAML client so the type graph matches the current schema.","Clear cached partial streaming state referencing old type definitions.","Verify all types referenced by the function's return type exist and resolve (enums, classes, aliases)."],"exampleFix":"// before: ignoring wrapped cause\nif let Err(e) = validate_streaming_state(&v) { log!(\"{e}\"); }\n// after: inspect the anyhow source\nlog!(\"{e:#}\") // prints full chain incl. distribute_type_with_meta cause","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match validate_streaming_state(&value) {\n    Err(StreamingError::DistributeTypeWithMetaFailure(src)) => {\n        log::error!(\"distribution failed: {src:#}\"); // full anyhow chain\n        Err(anyhow::anyhow!(src).context(\"schema/type mismatch during streaming\"))\n    }\n    other => other,\n}","preventionTips":["Keep generated clients in sync with the schema (regenerate often)","Print the error chain with {:#} to find the unresolved type","Clear stale streaming caches after schema changes"],"tags":["rust","streaming","type-resolution","wrapped-error"],"backgroundTag":"type-mismatch","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"}