{"record":{"id":"8d4fbd25485768e6","repo":"nodejs/node","slug":"gn-gen-failed","errorCode":null,"errorMessage":"gn gen failed","messagePattern":"gn gen failed","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"deps/v8/tools/dev/update-compile-commands.py","lineNumber":61,"sourceCode":"  return subprocess.call(cmd, shell=True)\n\ndef _Write(filename, content):\n  with open(filename, \"w\") as f:\n    f.write(content)\n\ndef PrepareBuildDir(arch, mode):\n  build_dir = os.path.join(\"out\", f\"{arch}.{mode}\")\n  if not os.path.exists(build_dir):\n    print(f\"# mkdir -p {build_dir}\")\n    os.makedirs(build_dir)\n  args_gn = os.path.join(build_dir, \"args.gn\")\n  if not os.path.exists(args_gn):\n    conf = gm.ManagedConfig(arch, mode, [])\n    _Write(args_gn, conf.get_gn_args())\n  build_ninja = os.path.join(build_dir, \"build.ninja\")\n  if not os.path.exists(build_ninja):\n    code = _Call(f\"gn gen {build_dir}\")\n    if code != 0: raise Exception(\"gn gen failed\")\n  else:\n    _Call(f\"autoninja -C {build_dir} build.ninja\")\n  return build_dir\n\ndef AddTargetsForArch(arch, combined):\n  build_dir = PrepareBuildDir(arch, \"debug\")\n  commands = compile_db.ProcessCompileDatabase(\n                compile_db.GenerateWithNinja(build_dir, [\"all\"]), [])\n  added = 0\n  for c in commands:\n    key = c[\"file\"]\n    if key not in combined:\n      combined[key] = c\n      added += 1\n  print(f\"{arch}: added {added} compile commands\")\n\ndef UpdateCompileCommands():\n  print(\">>> Updating compile_commands.json...\")","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/v8/tools/dev/update-compile-commands.py#L43-L79","documentation":"update-compile-commands.py's PrepareBuildDir() sets up an out/<arch>.<mode> build directory and runs `gn gen` to generate ninja files. If `gn gen <build_dir>` exits with a non-zero code (missing gn binary, bad args.gn, GN syntax error, or a stale build dir), it raises a plain Exception(\"gn gen failed\"). The error message carries no gn output, so the real cause is only visible in the printed _Call output.","triggerScenarios":"Calling AddTargetsForArch / PrepareBuildDir when `gn` is not on PATH, when the generated args.gn contains an invalid flag, when the out/<arch>.<mode> dir is partially initialized, or when gn itself errors (e.g. target CPU unsupported). The check is `code = _Call(...); if code != 0: raise`.","commonSituations":"First-time V8 checkout where gn (from depot_tools) is not yet on PATH; a stale out/ dir left over from a branch switch; an args.gn referencing a removed GN arg after a V8 upgrade; running outside depot_tools so `gn` is unresolved.","solutions":["Run `gn gen out/<arch>.debug` manually in the repo root to see the full GN error output, then fix the reported cause.","Ensure depot_tools is on PATH so the `gn` wrapper resolves (`which gn`).","Delete the offending out/<arch>.<mode> directory and let PrepareBuildDir regenerate args.gn from a clean state.","Validate the args.gn contents (is_component_build, target_cpu, v8_target_cpu, is_debug) against the current V8 GN schema."],"exampleFix":"// before\n    code = _Call(f\"gn gen {build_dir}\")\n    if code != 0: raise Exception(\"gn gen failed\")\n// after\n    code = _Call(f\"gn gen {build_dir}\")\n    if code != 0:\n      raise Exception(f\"gn gen failed (exit {code}) for {build_dir}; see output above\")","handlingStrategy":"validation","validationCode":"import shutil, subprocess\nif not shutil.which('gn'):\n    sys.exit('gn not on PATH; add depot_tools first.')\nrc = subprocess.call(['gn', 'gen', build_dir])\nif rc != 0:\n    sys.exit(f'gn gen failed (exit {rc}); rerun manually for full diagnostics')","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Run `gn gen out/<arch>.debug` manually before invoking update-compile-commands to surface GN errors with full output.","Keep depot_tools on PATH and synced so the `gn` wrapper is current.","Wipe out/<arch>.<mode> after branch switches to avoid stale args.gn."],"tags":["gn","ninja","build-config","v8-build","compile-commands"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}