BoundaryML/baml · error · Error

Value already exists.

Error message

Value ${name} already exists.

What it means

JavaScript type-builder validation: addValue was called with an enum value name already present in this EnumBuilder's set. Duplicate variants are rejected to keep the generated enum well-formed; the set membership check fires before the value is registered with the underlying builder.

Solutions

  1. Check this.values / listValues() for the name before calling addValue
  2. Make registration idempotent: skip names that already exist instead of adding again
  3. Reset or re-create the EnumBuilder if you need to rebuild the value set from scratch

Example fix

// before
enumBuilder.addValue('ACTIVE'); // second call throws
// after
if (!enumBuilder.listValues().some(([n]) => n === 'ACTIVE')) {
  enumBuilder.addValue('ACTIVE');
}
Defensive patterns

Strategy: validation

Validate before calling

const existing = new Set(enumBuilder.listValues().map(([n]) => n));
for (const v of newValues) if (!existing.has(v)) enumBuilder.addValue(v);

Try / catch

try { enumBuilder.addValue(name); }
catch (e) { if (!String(e.message).includes('already exists')) throw e; }

Prevention

When it happens

Trigger: Calling EnumBuilder.addValue('STATUS') twice for the same enum, or re-running registration logic (e.g. a hot-reload or rebuild pass) without clearing the builder's value set.

Common situations: Dynamically generating enums from external schemas that contain duplicate keys; idempotency bugs where setup code runs more than once; merging enum values from two sources with overlapping names.

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


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

Appendix: source

Thrown at engine/language_client_typescript/type_builder.js:212

    value(name) {
        if (!this.values.has(name)) {
            throw new Error(`Value ${name} not found.`);
        }
        return new EnumValueViewer();
    }
}
exports.EnumViewer = EnumViewer;
class EnumValueViewer {
    constructor() { }
}
exports.EnumValueViewer = EnumValueViewer;
class EnumBuilder extends EnumAst {
    constructor(tb, name, values = new Set()) {
        super(tb, name, values);
    }
    addValue(name) {
        if (this.values.has(name)) {
            throw new Error(`Value ${name} already exists.`);
        }
        this.values.add(name);
        return this.bldr.value(name);
    }
    listValues() {
        return Array.from(this.values).map((name) => [name, this.bldr.value(name)]);
    }
    value(name) {
        return this.bldr.value(name);
    }
}
exports.EnumBuilder = EnumBuilder;

View on GitHub (pinned to bd85ce9dee)