{"record":{"id":"9fa6358f43f29e0b","repo":"abhigyanpatwari/GitNexus","slug":"cfg-go-unresolved-goto-label-label-routed","errorCode":null,"errorMessage":"[cfg] Go: unresolved goto label \"${label}\" routed to EXIT (${froms.length} site(s))","messagePattern":"\\[cfg\\] Go: unresolved goto label \"(.+?)\" routed to EXIT \\((.+?) site\\(s\\)\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"gitnexus/src/core/ingestion/cfg/visitors/go.ts","lineNumber":495,"sourceCode":"    if (normalExits.length > 0) {\n      this.builder.connect(normalExits, lifo[0].entry, 'return');\n      for (let i = 0; i + 1 < lifo.length; i++) {\n        this.builder.edge(lifo[i].entry, lifo[i + 1].entry, 'finally-return');\n      }\n    }\n    // After the outermost defer runs, control reaches EXIT.\n    return [lifo[lifo.length - 1].entry];\n  }\n\n  /**\n   * Route any forward `goto`s whose label never appeared in the function to EXIT\n   * (single-exit preserved) and log them so a dropped jump is never silent (R4).\n   * Called once after the body walk.\n   */\n  flushGotos(builder: CfgBuilder): void {\n    for (const [label, froms] of this.pendingGotos) {\n      // eslint-disable-next-line no-console\n      console.warn(\n        `[cfg] Go: unresolved goto label \"${label}\" routed to EXIT (${froms.length} site(s))`,\n      );\n      for (const from of froms) builder.edge(from, builder.exitIndex, 'seq');\n    }\n    this.pendingGotos.clear();\n  }\n\n  private visitIf(stmt: SyntaxNode): TraversalResult {\n    const cond = stmt.childForFieldName('condition') ?? stmt;\n    const init = stmt.childForFieldName('initializer');\n    // The header block carries the (optional) initializer's facts AND the\n    // condition's facts — both evaluate before the branch.\n    const header = this.builder.newBlock(\n      init ? startLineOf(init) : startLineOf(stmt),\n      endLineOf(cond),\n      init ? `${init.text}; ${cond.text}` : cond.text,\n      'normal',\n      this.harvest.facts(cond),","sourceCodeStart":477,"sourceCodeEnd":513,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/aac7515d2a8c50a1f8f923c6fb77218b333560d6/gitnexus/src/core/ingestion/cfg/visitors/go.ts#L477-L513","documentation":"flushGotos() in the Go CFG visitor runs once after the body walk: any forward goto whose label never appeared in the function is routed to the EXIT node to preserve a single-exit graph, and each unresolved label is logged via console.warn. In valid Go the compiler rejects undefined labels, so this warning almost always indicates generated/partial files or a parse-level divergence rather than a user bug.","triggerScenarios":"Analyzing partial or syntactically odd Go files (codegen templates, testdata) where a goto's label sits in code the walker never registered; malformed Go that would not compile but still parses.","commonSituations":"Codegen templates or example snippets committed as .go files; truncated files; vendored generated code whose build-time transformations are not visible to the parser.","solutions":["Verify the file compiles (go build / go vet the module) — in valid Go every goto label exists","Exclude codegen templates and testdata containing such gotos from analysis via ignore rules","Accept the EXIT routing — it keeps the CFG single-exit and the dropped jump is reported rather than silent"],"exampleFix":"// before — template file with a goto whose label lives in commented-out code\ngoto retry  // label `retry:` only exists under a build tag\n\n// after — restore the label or remove the goto\nretry:\n// ...","handlingStrategy":"fallback","validationCode":"// Pre-check: in valid Go every goto label is defined in the same function\nconst gotoLabels = [...source.matchAll(/\\bgoto\\s+(\\w+)\\b/g)].map((m) => m[1]);\nconst defined = new Set([...source.matchAll(/^\\s*(\\w+)\\s*:/gm)].map((m) => m[1]));\nconst unresolved = gotoLabels.filter((l) => !defined.has(l));\nif (unresolved.length > 0) {\n  console.warn(`file would not compile — gotos without labels: ${[...new Set(unresolved)].join(', ')}`);\n}","typeGuard":"function goFileHasResolvableLabels(source: string): boolean {\n  const gotos = [...source.matchAll(/\\bgoto\\s+(\\w+)\\b/g)].map((m) => m[1]);\n  const defined = new Set([...source.matchAll(/^\\s*(\\w+)\\s*:/gm)].map((m) => m[1]));\n  return gotos.every((l) => defined.has(l));\n}","tryCatchPattern":null,"preventionTips":["Run go build / go vet over the module before indexing — the compiler rejects undefined labels","Keep codegen templates and partial Go snippets out of indexed trees (testdata dirs, .tmpl extensions)","Treat the warning as benign degradation: unresolved gotos are routed to EXIT with a log line"],"tags":["cfg","go","goto","generated-code"],"backgroundTag":"unresolved-goto-label","analyzedSha":"aac7515d2a8c50a1f8f923c6fb77218b333560d6","analyzedAt":"2026-08-20T23:29:22.980Z","contentChangedAt":"2026-08-20T23:29:22.980Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}