{"record":{"id":"8dcbf0fa62f4ca2d","repo":"BoundaryML/baml","slug":"class-not-found-objects","errorCode":null,"errorMessage":"Class not found: {}","messagePattern":"Class not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_cffi/src/raw_ptr_wrapper/type_builder/objects.rs","lineNumber":215,"sourceCode":"                }\n            }\n        };\n\n        builder.mode(target_mode)\n    }\n\n    fn cls(\n        &self,\n        rt: &BamlRuntime,\n    ) -> anyhow::Result<std::sync::Arc<std::sync::Mutex<type_builder::ClassBuilder>>> {\n        // if the IR defines the class, then its always valid\n        if rt.ir.find_class(self.class_name.as_str()).is_ok() {\n            let cls = self.type_builder.upsert_class(self.class_name.as_str());\n            return Ok(cls);\n        }\n\n        let Some(cls) = self.type_builder.maybe_get_class(self.class_name.as_str()) else {\n            anyhow::bail!(\"Class not found: {}\", self.class_name);\n        };\n        Ok(cls)\n    }\n\n    pub fn r#type(&self, rt: &BamlRuntime) -> anyhow::Result<TypeIR> {\n        self.mode.at_least(NodeRW::ReadOnly)?;\n        let _ = self.cls(rt)?;\n\n        Ok(TypeIR::class(self.class_name.as_str()))\n    }\n\n    pub fn list_properties(&self, rt: &BamlRuntime) -> anyhow::Result<Vec<ClassPropertyBuilder>> {\n        self.mode.at_least(NodeRW::ReadOnly)?;\n\n        let lock = self.cls(rt)?;\n        let builder = lock.lock().unwrap();\n\n        let ir_properties = match rt.ir.find_class(self.class_name.as_str()) {","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_cffi/src/raw_ptr_wrapper/type_builder/objects.rs#L197-L233","documentation":"ClassBuilder::cls resolves the underlying class node by first checking the runtime IR, then the TypeBuilder itself. If the class name is found in neither, it bails with 'Class not found'. All ClassBuilder operations (type, list_properties, set_alias, etc.) go through this resolver, so this error surfaces from any of them.","triggerScenarios":"Using a ClassBuilder whose class name was removed or never registered on the attached TypeBuilder/IR, e.g. calling cb.set_alias / cb.list_properties on a stale or misnamed builder.","commonSituations":"Holding a ClassBuilder across a rebuild of the runtime/TypeBuilder; constructing ClassBuilder manually with a wrong name; renaming the class in BAML source while cached builders still use the old name.","solutions":["Recreate the ClassBuilder from the current TypeBuilder via tb.class(rt, name)","Verify the class name matches the BAML source exactly","Avoid caching builders across runtime/TypeBuilder rebuilds"],"exampleFix":"// before\nlet cb = ClassBuilder::new(old_tb, \"Resume\");\ncb.set_alias(rt, \"CV\")?; // stale builder -> class not found\n// after\nlet cb = tb.class(rt, \"Resume\")?;\ncb.set_alias(rt, \"CV\")?;","handlingStrategy":"try-catch","validationCode":"// re-resolve builder from live TypeBuilder before use\nlet cb = tb.class(rt, \"Resume\")?;","typeGuard":null,"tryCatchPattern":"match cb.set_alias(rt, alias) {\n    Ok(_) => ...,\n    Err(e) if e.to_string().contains(\"Class not found\") => {\n        let cb = tb.class(rt, \"Resume\")?;\n        cb.set_alias(rt, alias)?;\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Do not cache ClassBuilders across runtime rebuilds","Always obtain builders from the current TypeBuilder via tb.class(...)","Keep class names in sync with BAML source changes"],"tags":["type-builder","class","not-found","rust"],"backgroundTag":"class-not-found","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}