abhigyanpatwari/GitNexus · warning

[cfg] Go buildFunctionCfg skipped a function in ${filePath}:

Error message

[cfg] Go buildFunctionCfg skipped a function in ${filePath}: ${String(err)}

What it means

During indexing GitNexus builds a per-function control-flow graph (CFG) with a Go tree-sitter visitor. buildFunctionCfg wraps the walk — including defer-chain threading (walk.finishDefers, LIFO) and goto flushing (walk.flushGotos) — in a catch-all: any throw from an unexpected AST shape is logged with console.warn and only that function's CFG is skipped (returns undefined), protecting the file's language group ('R4' isolation).

Source

Thrown at gitnexus/src/core/ingestion/cfg/visitors/go.ts:873

    const paramFacts = harvest.paramFacts();
    if (paramFacts) builder.attachFacts(builder.entryIndex, paramFacts);

    const walk = new GoCfgWalk(builder, harvest);
    const res = walk.visitSeq(body.namedChildren.filter((c) => c.type !== 'comment'));

    builder.edge(builder.entryIndex, res ? res.entry : builder.exitIndex, 'seq');
    // Normal fall-off threads through the active `defer` chain (LIFO) → EXIT.
    const normalExits = res ? res.exits : [builder.entryIndex];
    const afterDefers = walk.finishDefers(normalExits);
    builder.connect(afterDefers, builder.exitIndex, 'seq');
    walk.flushGotos(builder);
    return builder.finish(harvest.bindingTable());
  } catch (err) {
    // Never throw out of buildFunctionCfg — a malformed AST shape must skip only
    // this one function's CFG, never drop the whole file's language group (R4).
    // eslint-disable-next-line no-console
    console.warn(`[cfg] Go buildFunctionCfg skipped a function in ${filePath}: ${String(err)}`);
    return undefined;
  }
}

/** Whether a node is a Go function this visitor builds a CFG for. */
function isFunction(node: SyntaxNode): boolean {
  return GO_FUNCTION_TYPES.has(node.type);
}

/** The Go CFG visitor. */
export function createGoCfgVisitor(): CfgVisitor<SyntaxNode> {
  return { buildFunctionCfg, isFunction };
}

export { GO_FUNCTION_TYPES };

View on GitHub (pinned to aac7515d2a)

Solutions

  1. Read the ${String(err)} portion of the warning for the underlying exception
  2. Index only the affected file and inspect its parse tree around the failing function
  3. Reinstall dependencies to resync the vendored grammar, or patch the Go visitor for the shape
  4. Re-run analyze --index-only to rebuild the CFG layer
  5. Accept the skip: only that function's CFG (including its defer threading) is absent
Defensive patterns

Strategy: fallback

Validate before calling

// prescreen: catch ERROR/MISSING nodes before the CFG walk
if (tree.rootNode.hasError) fixSourceOrExclude(file);

Try / catch

const cfg = visitor.buildFunctionCfg(fn, ctx);
if (cfg === undefined) continue; // warned skip; defer/goto threading lost for this fn

Prevention

When it happens

Trigger: A Go function body containing a construct the walker does not model: complex goto/label shapes, generic (type-parameterized) function bodies with unexpected node kinds, or ERROR/MISSING nodes from syntactically invalid source, causing a throw during visitSeq or the defer/goto bookkeeping.

Common situations: Indexing huge generated .pb.go protobuf stubs with unusual shapes; grammar version drift in vendored tree-sitter-go; files with syntax errors; newer Go language features the visitor predates.

Related errors


AI-assisted analysis of abhigyanpatwari/GitNexus@aac7515d2a (2026-08-20). Data as JSON: /api/errors/20a5dfecc4082ddd. Report an issue: GitHub.