{"record":{"id":"4d3aaf7adff8c594","repo":"BoundaryML/baml","slug":"unsupported-object-type-for-testing","errorCode":null,"errorMessage":"Unsupported object type for testing: {:?}","messagePattern":"Unsupported object type for testing: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-vm/src/test.rs","lineNumber":136,"sourceCode":"                let VmObject::Enum(vm_enum) = &vm.objects[variant.enm] else {\n                    anyhow::bail!(\"Enum not found for variant: {:?}\", variant);\n                };\n\n                Ok(Object::Variant(Variant {\n                    enm: vm_enum.name.clone(),\n                    variant: vm_enum.variant_names[variant.index].clone(),\n                }))\n            }\n\n            VmObject::Media(media) => Ok(Object::Media(media.clone())),\n\n            VmObject::Function(f) => Ok(Object::Function(f.name.clone())),\n\n            VmObject::Class(c) => Ok(Object::Class(c.name.clone())),\n\n            VmObject::Enum(e) => Ok(Object::Enum(e.name.clone())),\n\n            _ => anyhow::bail!(\"Unsupported object type for testing: {:?}\", obj),\n        }\n    }\n\n    pub fn instance(class: &str, fields: IndexMap<&str, Value>) -> Self {\n        Object::Instance(Instance {\n            class: class.to_string(),\n            fields: Instance::fields(fields),\n        })\n    }\n\n    /// Shorthand for creating a function object reference.\n    pub fn function(name: &str) -> Self {\n        Object::Function(name.to_string())\n    }\n\n    /// Shorthand for creating a class object reference.\n    pub fn class(name: &str) -> Self {\n        Object::Class(name.to_string())","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-vm/src/test.rs#L118-L154","documentation":"from_vm_object only maps a fixed subset of VmObject kinds (Function, Class, Enum, and earlier handled kinds) into the test Object representation. Any other kind reaches the catch-all arm and is rejected. It exists to make unsupported conversions explicit rather than silently dropping them.","triggerScenarios":"Calling from_vm_object with a VmObject that is not one of the explicitly handled kinds (e.g. Instance, Variant, raw/primitive objects held differently), so it falls into the `_ =>` arm.","commonSituations":"Adding a new VmObject variant to the VM and forgetting to extend the match in test.rs; tests serializing watch payloads that contain instance objects.","solutions":["Extend the match in from_vm_object to explicitly handle the new VmObject kind","If instances are needed for tests, add an arm like `VmObject::Instance(i) => Ok(Object::Instance(...))`","Otherwise filter out unsupported kinds before calling from_vm_object"],"exampleFix":"// before\n_ => anyhow::bail!(\"Unsupported object type for testing: {:?}\", obj),\n// after\nVmObject::Instance(inst) => Ok(Object::Instance(Instance {\n    class: inst.class.name.clone(),\n})),\n_ => anyhow::bail!(\"Unsupported object type for testing: {:?}\", obj),","handlingStrategy":"type-guard","validationCode":"fn is_test_convertible(obj: &VmObject) -> bool {\n    matches!(obj, VmObject::Function(_) | VmObject::Class(_) | VmObject::Enum(_) | VmObject::Variant(_))\n}","typeGuard":"matches!(obj, VmObject::Function(_) | VmObject::Class(_) | VmObject::Enum(_))","tryCatchPattern":"match Object::from_vm_object(&vm, obj) { Ok(o) => o, Err(e) => { log::debug!(\"skipping unconvertible object: {e}\"); continue; } }","preventionTips":["When adding a VmObject variant, search for exhaustive matches on VmObject and update them","Use #[non_exhaustive]-style discipline and compile-time match checks to catch missing arms","Filter unsupported kinds before conversion in test helpers"],"tags":["vm","unsupported","conversion"],"backgroundTag":"unsupported-operation","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"}