{"record":{"id":"e6f0a1edd4f1c21a","repo":"oven-sh/bun","slug":"failed-to-generate-classes","errorCode":null,"errorMessage":"Failed to generate classes","messagePattern":"Failed to generate classes","errorType":"exception","errorClass":"AggregateError","httpStatus":null,"severity":"error","filePath":"src/codegen/generate-classes.ts","lineNumber":2457,"sourceCode":"      );\n      continue;\n    }\n\n    console.log(\"Found\", result.default.length, \"classes from\", file);\n    for (let { name, proto = {}, klass = {} } of result.default) {\n      let protoProps = Object.keys(proto).length ? `${Object.keys(proto).length} fields` : \"\";\n      let klassProps = Object.keys(klass).length ? `${Object.keys(klass).length} class fields` : \"\";\n      let props = [protoProps, klassProps].filter(Boolean).join(\", \");\n      if (props.length) props = ` (${props})`;\n      console.log(`  - ${name}` + props);\n    }\n\n    for (const def of result.default) def._classesFilePath = filepath;\n    classes.push(...result.default);\n  }\n\n  if (errors.length) {\n    throw new AggregateError(errors, \"Failed to generate classes\");\n  }\n}\nclasses.sort((a, b) => (a.name < b.name ? -1 : 1));\n\n// sort all the prototype keys and klass keys\nfor (const obj of classes) {\n  let { klass = {}, proto = {} } = obj;\n\n  klass = Object.fromEntries(Object.entries(klass).sort(([a], [b]) => a.localeCompare(b)));\n  proto = Object.fromEntries(Object.entries(proto).sort(([a], [b]) => a.localeCompare(b)));\n\n  obj.klass = klass;\n  obj.proto = proto;\n}\n\nconst GENERATED_CLASSES_FOOTER = `\n\ntypedef SYSV_ABI void (*CppStructuredCloneableSerializeFunction)(CloneSerializer*, const uint8_t*, uint32_t);","sourceCodeStart":2439,"sourceCodeEnd":2475,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/src/codegen/generate-classes.ts#L2439-L2475","documentation":"The class generator collects every failure encountered while importing/parsing the *.classes.ts files into an array and throws them all at once wrapped in an AggregateError. 'Failed to generate classes' is therefore an umbrella: the real diagnostics are the individual errors inside `errors` (accessed via `error.errors`), each typically a syntax error, missing import, or runtime exception in one of the definition files.","triggerScenarios":"Any exception while a .classes.ts module is imported: TypeScript/JS syntax errors, importing a symbol that no longer exists, a top-level expression throwing (e.g. calling a helper with undefined), or a file whose default export is not a valid class definition object.","commonSituations":"Mid-refactor builds after renaming a type or moving a file referenced by class definitions; merge conflicts inside .classes.ts files leaving invalid syntax.","solutions":["Inspect the aggregated causes — the message itself is generic; run with the AggregateError printed (e.g. `catch (e) { console.error(e.errors ?? e) }` or look at the build log lines above) to see each file's real error","Fix the first per-file error (usually a syntax/import problem in the named .classes.ts) and re-run; later errors often cascade from the first","If a file was recently added, verify it has a default export shaped like other .classes.ts files"],"exampleFix":"// reading the real causes when wrapping the codegen step\ntry {\n  await import(\"./generate-classes.ts\");\n} catch (e) {\n  if (e instanceof AggregateError) for (const inner of e.errors) console.error(inner);\n  else throw e;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isAggregateOfClassErrors(e: unknown): e is AggregateError {\n  return e instanceof AggregateError && Array.isArray(e.errors) && e.message === \"Failed to generate classes\";\n}","tryCatchPattern":"try {\n  await generate();\n} catch (e) {\n  if (isAggregateOfClassErrors(e)) {\n    for (const cause of e.errors) console.error(cause); // real per-file diagnostics\n    process.exitCode = 1;\n  } else throw e;\n}","preventionTips":["Always read e.errors of the AggregateError — the umbrella message carries no diagnostic content","Run `bun run build` after moving/renaming symbols referenced by .classes.ts files; stale imports surface here first"],"tags":["codegen","classes","aggregate-error","build"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}