{"record":{"id":"c195e64a9f2c6d76","repo":"oven-sh/bun","slug":"missing-output-directory","errorCode":null,"errorMessage":"Missing output directory","messagePattern":"Missing output directory","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/codegen/generate-node-errors.ts","lineNumber":7,"sourceCode":"import path from \"node:path\";\nimport NodeErrors from \"../jsc/bindings/ErrorCode.ts\";\nimport { writeIfNotChanged } from \"./helpers.ts\";\nconst outputDir = process.argv[2];\n\nif (!outputDir) {\n  throw new Error(\"Missing output directory\");\n}\n\nconst extra_count = NodeErrors.map(x => x.slice(3))\n  .filter(x => x.length > 0)\n  .reduce((ac, cv) => ac + cv.length, 0);\nconst count = NodeErrors.length + extra_count;\n\nif (count > 1 << 16) {\n  // increase size of the enums below to have more tags\n  throw new Error(`NodeError can't fit ${count} codes in a u16`);\n}\n\nlet enumHeader = ``;\nlet listHeader = ``;\nlet rustConsts = ``;\nlet rustAliases = ``;\nlet rustCodeStr = ``;\n","sourceCodeStart":1,"sourceCodeEnd":25,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/src/codegen/generate-node-errors.ts#L1-L25","documentation":"generate-node-errors.ts is invoked as `bun src/codegen/generate-node-errors.ts <outputDir>` and reads its sole argument from process.argv[2]. If the script is run with no arguments (standalone, or via a wrapper that drops the argument), it throws immediately with this message before generating the Node error-code tables from src/jsc/bindings/ErrorCode.ts.","triggerScenarios":"Running `bun src/codegen/generate-node-errors.ts` with no CLI argument; a custom build/package.json script that forwards arguments incorrectly (e.g. quoting that swallows the path); an updated build pipeline that stopped passing the output dir.","commonSituations":"Contributors running the generator manually to iterate on error codes; scripts/build pipeline refactors that break argument forwarding.","solutions":["Pass the output directory explicitly: `bun src/codegen/generate-node-errors.ts src/generated` (match the directory the normal build uses)","If invoking through a wrapper script, print process.argv inside it to confirm the argument survives quoting/expansion","Compare with how scripts/build invokes the generator (search the build scripts for generate-node-errors) and mirror that call"],"exampleFix":"# before\nbun src/codegen/generate-node-errors.ts\n\n# after\nbun src/codegen/generate-node-errors.ts src/node/error_codes","handlingStrategy":"validation","validationCode":"// wrap the generator so it cannot start without an output dir\nimport { spawnSync } from \"node:child_process\";\nconst outDir = process.argv[2];\nif (!outDir) {\n  console.error(\"usage: bun run gen-node-errors <outputDir>\");\n  process.exit(1);\n}\nspawnSync(process.execPath, [\"src/codegen/generate-node-errors.ts\", outDir], { stdio: \"inherit\" });","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Invoke the generator exactly as scripts/build does — search the build scripts for its canonical invocation","When writing wrapper scripts, forward arguments explicitly rather than via loose quoting"],"tags":["codegen","node-compat","cli-usage","build"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}