{"record":{"id":"4717e33d9dc2fc94","repo":"BoundaryML/baml","slug":"enum-name-already-exists-type-builder","errorCode":null,"errorMessage":"Enum ${name} already exists","messagePattern":"Enum (.+?) already exists","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"engine/language_client_typescript/typescript_src/type_builder.ts","lineNumber":113,"sourceCode":"    properties: Properties[],\n  ): ClassBuilder<Name, Properties> {\n    return new ClassBuilder(this.tb, name, new Set(properties))\n  }\n\n  enumViewer<Name extends string, Values extends string>(name: Name, values: Values[]): EnumViewer<Name, Values> {\n    return new EnumViewer(this.tb, name, new Set(values))\n  }\n\n  enumBuilder<Name extends string, Values extends string>(name: Name, values: Values[]): EnumBuilder<Name, Values> {\n    return new EnumBuilder(this.tb, name, new Set(values))\n  }\n\n  addClass<Name extends string>(name: Name): ClassBuilder<Name> {\n    if (this.classes.has(name)) {\n      throw new Error(`Class ${name} already exists`)\n    }\n    if (this.enums.has(name)) {\n      throw new Error(`Enum ${name} already exists`)\n    }\n    this.classes.add(name)\n    return new ClassBuilder(this.tb, name)\n  }\n\n  addEnum<Name extends string>(name: Name): EnumBuilder<Name> {\n    if (this.classes.has(name)) {\n      throw new Error(`Class ${name} already exists`)\n    }\n    if (this.enums.has(name)) {\n      throw new Error(`Enum ${name} already exists`)\n    }\n    this.enums.add(name)\n    return new EnumBuilder(this.tb, name)\n  }\n\n  addBaml(baml: string): void {\n    this.tb.addBaml(baml, this.runtime)","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_typescript/typescript_src/type_builder.ts#L95-L131","documentation":"TypeBuilder.addClass throws 'Enum <name> already exists' when the requested class name is already taken by a previously registered enum. Classes and enums share one namespace, so addClass refuses names that collide with enums as well as other classes.","triggerScenarios":"Calling typeBuilder.addClass('Status') after typeBuilder.addEnum('Status') was called on the same builder.","commonSituations":"Merging schemas from multiple sources into one builder where a name exists as both an enum and a class; scripted registration from config files with overlapping names.","solutions":["Use a different name for the class or the enum so they do not collide.","Track registered names across helpers and skip re-registration.","Check whether an addEnum call intended to be addClass (or vice versa)."],"exampleFix":"// before\ntb.addEnum('Status')\ntb.addClass('Status') // throws: taken by enum\n// after\ntb.addEnum('Status')\ntb.addClass('StatusRecord') // distinct name","handlingStrategy":"validation","validationCode":"// classes and enums share a namespace; check both before registering\nif (classNames.has(name) || enumNames.has(name)) throw new Error(`name collision: ${name}`)","typeGuard":null,"tryCatchPattern":"try {\n  const cls = tb.addClass(name)\n} catch (e) {\n  if (/Enum .* already exists/.test(e.message)) throw new Error(`'${name}' is registered as an enum; pick another name`)\n  throw e\n}","preventionTips":["Keep a single registry of all registered names (classes + enums).","Adopt naming conventions distinguishing enums (e.g. suffix 'Kind').","Validate schema inputs for duplicate names before building."],"tags":["typescript","schema","naming-collision","type-builder"],"backgroundTag":"file-already-exists","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"}