BoundaryML/baml · error · Error

Value ${name} not found.

Error message

Value ${name} not found.

What it means

EnumAst.value (viewer API) throws 'Value <name> not found.' when the requested value is not among the enum's registered values. The viewer tracks value names in a Set and fails fast on unknown lookups rather than returning a null viewer.

Source

Thrown at engine/language_client_typescript/typescript_src/type_builder.ts:272

  }

  type(): FieldType {
    return this.bldr.field()
  }
}

export class EnumViewer<EnumName extends string, T extends string = string> extends EnumAst<EnumName, T> {
  constructor(tb: _TypeBuilder, name: EnumName, values: Set<T | string> = new Set()) {
    super(tb, name, values)
  }

  listValues(): Array<[string, EnumValueViewer]> {
    return Array.from(this.values).map((name) => [name, new EnumValueViewer()])
  }

  value(name: string): EnumValueViewer {
    if (!this.values.has(name)) {
      throw new Error(`Value ${name} not found.`)
    }
    return new EnumValueViewer()
  }
}

export class EnumValueViewer {
  constructor() {}
}

export class EnumBuilder<EnumName extends string, T extends string = string> extends EnumAst<EnumName, T> {
  constructor(tb: _TypeBuilder, name: EnumName, values: Set<T | string> = new Set()) {
    super(tb, name, values)
  }

  addValue<S extends string>(name: RestrictNot<EnumName, S, T>): EnumValueBuilder {
    if (this.values.has(name)) {
      throw new Error(`Value ${name} already exists.`)
    }

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Call listValues() first and verify the exact value name before lookup.
  2. Fix casing/spelling in the value lookup.
  3. Register the missing value on the EnumBuilder before inspecting it.

Example fix

// before
const v = enumViewer.value('RED') // throws if absent
// after
const names = enumViewer.listValues().map(([n]) => n)
const v = names.includes('RED') ? enumViewer.value('RED') : null
Defensive patterns

Strategy: validation

Validate before calling

const exists = enumViewer.listValues().some(([n]) => n === name)
if (!exists) throw new Error(`enum value '${name}' not registered`)

Try / catch

try {
  const v = enumViewer.value(name)
} catch (e) {
  if (e.message.includes('not found')) return null
  throw e
}

Prevention

When it happens

Trigger: Calling enumViewer.value('RED') where 'RED' was never added via EnumBuilder value registration, or with mismatched casing (e.g. 'red' vs 'RED').

Common situations: Inspecting a dynamic enum whose values come from a database or config that changed; lookup names sourced from user input.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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