{"record":{"id":"6ec8a96e66d1a340","repo":"BoundaryML/baml","slug":"e-type-builder","errorCode":null,"errorMessage":"{e}","messagePattern":"\\{e\\}","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"engine/language_client_ruby/ext/ruby_ffi/src/types/type_builder.rs","lineNumber":130,"sourceCode":"        Ok(baml_types::TypeIR::union(\n            types\n                .into_iter()\n                .map(|t| t.inner.lock().unwrap().clone())\n                .collect(),\n        )\n        .into())\n    }\n\n    pub fn add_baml(\n        ruby: &magnus::Ruby,\n        rb_self: &TypeBuilder,\n        baml: String,\n        runtime: &crate::BamlRuntimeFfi,\n    ) -> Result<()> {\n        rb_self\n            .inner\n            .add_baml(&baml, &runtime.inner)\n            .map_err(|e| magnus::Error::new(ruby.exception_runtime_error(), e.to_string()))\n    }\n\n    // this implements ruby's friendly to_s method for converting objects to strings\n    // when someone calls .to_s on a typebuilder in ruby, this method gets called\n    // under the hood, it uses rust's display trait to format everything nicely\n    // by using the same display logic across languages, we keep things consistent\n    // this helps make debugging and logging work the same way everywhere :D\n    pub fn to_s(&self) -> String {\n        self.inner.to_string()\n    }\n\n    pub fn define_in_ruby(module: &RModule) -> Result<()> {\n        let cls = module.define_class(\"TypeBuilder\", class::object())?;\n\n        cls.define_singleton_method(\"new\", function!(TypeBuilder::new, 0))?;\n        cls.define_method(\"to_s\", method!(TypeBuilder::to_s, 0))?;\n        cls.define_method(\"enum\", method!(TypeBuilder::r#enum, 1))?;\n        // TODO: Not exposed, Ruby doesn't work right now.","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_ruby/ext/ruby_ffi/src/types/type_builder.rs#L112-L148","documentation":"TypeBuilder#add_baml adds BAML source (and the runtime) to a type builder. Any error returned by the Rust add_baml implementation (parse errors, duplicate types, invalid references) is converted into a Ruby RuntimeError carrying e.to_string().","triggerScenarios":"Calling type_builder.add_baml(baml_string, runtime) with BAML source that fails to parse/merge, or with a runtime not compatible with the builder.","commonSituations":"Typo or syntax error in the BAML snippet, re-adding a file that defines an existing type/class/enum name, referencing types not yet defined, or mismatched runtime instance.","solutions":["Fix the BAML syntax/naming error reported in the message.","Ensure add_baml is called only once per unique type and that dependencies are added before dependents.","Pass the same BamlRuntimeFfi instance the client was built with."],"exampleFix":"// before\ntb.add_baml(broken_baml, runtime) # RuntimeError: parse error...\n// after\nbegin\n  tb.add_baml(valid_baml, runtime)\nrescue RuntimeError => e\n  raise \"Invalid BAML source: #{e.message}\"\nend","handlingStrategy":"validation","validationCode":"# validate BAML source parses before add_baml, e.g. run `baml-cli validate` or keep source in .baml files tested in CI","typeGuard":null,"tryCatchPattern":"begin\n  tb.add_baml(src, runtime)\nrescue RuntimeError => e\n  raise \"add_baml failed: #{e.message}\"\nend","preventionTips":["Lint/parse BAML source in CI before loading at runtime.","Avoid defining duplicate type names across add_baml calls.","Always pass the same runtime instance used to build clients."],"tags":["ruby","ffi","baml","typebuilder","parse-error"],"backgroundTag":"invalid-argument-value","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}