BoundaryML/baml · error · napi::Error

attempted to read a property that has no defined type, this…

Error message

attempted to read a property that has no defined type, this is likely an internal bug

What it means

ClassPropertyViewer.getType() could not obtain a defined type for the property from the underlying runtime type builder; r#type() returned None. The library treats a property without a type as an internal inconsistency, so it raises an anyhow-derived error labelled an internal bug.

Solutions

  1. Always set the property type (bldr.property(name).setType(...)) before reading it via property()/getType()
  2. Check that you are viewing the property after addProperty completed with a type argument
  3. If iterating properties, skip or default-handle properties whose type is not yet set
  4. Report to BAML if the property was definitely given a type — it indicates a binding bug

Example fix

// before
const p = clsBuilder.addProperty("name"); // type set later, too late
// after
const p = clsBuilder.addProperty("name", "string");
Defensive patterns

Strategy: validation

Validate before calling

if (!clsBuilder.listProperties().some(([n]) => n === propName)) throw new Error('unknown property');

Type guard

null

Try / catch

try { const t = prop.getType(); } catch (e) {
  if (e.message.includes('no defined type')) { /* property has no type yet */ }
  else throw e;
}

Prevention

When it happens

Trigger: Inspecting a property created without calling setType()/setType first (via ClassBuilder.addProperty with an unset type path); viewing a property whose type was removed or never initialized in the type builder; races where the underlying type-builder object was reset before viewing.

Common situations: Iterating listProperties() on a freshly added class property that has no type yet; dynamically constructed type builders where a property was declared but never given a type; N-API handle lifecycle issues after runtime teardown.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/f1ed41397923cc09. Report an issue: GitHub.

Appendix: source

Thrown at engine/language_client_typescript/src/types/type_builder.rs:310

#[napi]
impl ClassPropertyBuilder {
    #[napi]
    pub fn set_type(&self, field_type: &FieldType) -> Self {
        self.inner
            .lock()
            .unwrap()
            .set_type(field_type.inner.lock().unwrap().clone());
        self.inner.clone().into()
    }

    #[napi]
    pub fn get_type(&self) -> napi::Result<FieldType> {
        self.inner
            .lock()
            .unwrap()
            .r#type()
            .map(FieldType::from)
            .ok_or_else(|| crate::errors::from_anyhow_error(anyhow::anyhow!(
                "attempted to read a property that has no defined type, this is likely an internal bug"
            )))
    }

    #[napi]
    pub fn alias(&self, alias: Option<String>) -> Self {
        self.inner.lock().unwrap().with_meta(
            "alias",
            alias.map_or(baml_types::BamlValue::Null, BamlValue::String),
        );
        self.inner.clone().into()
    }

    #[napi]
    pub fn description(&self, description: Option<String>) -> Self {
        self.inner.lock().unwrap().with_meta(
            "description",
            description.map_or(baml_types::BamlValue::Null, BamlValue::String),

View on GitHub (pinned to bd85ce9dee)