abhigyanpatwari/GitNexus · warning

[cfg] Java buildFunctionCfg skipped a function in ${filePath

Error message

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

What it means

During indexing GitNexus builds a per-function control-flow graph (CFG) with a Java tree-sitter visitor. buildFunctionCfg wraps the body walk (visitSeq over namedChildren filtered by isComment) 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), so one malformed function cannot drop the file's language group ('R4' isolation).

Source

Thrown at gitnexus/src/core/ingestion/cfg/visitors/java.ts:1093

      builder.edge(builder.entryIndex, blk, 'seq');
      builder.edge(blk, builder.exitIndex, 'return');
      return builder.finish(harvest.bindingTable());
    }

    const walk = new JavaCfgWalk(builder, harvest);
    const res = walk.visitSeq(body.namedChildren.filter((c) => !isComment(c)));
    if (!res) {
      builder.edge(builder.entryIndex, builder.exitIndex, 'seq'); // empty body
      return builder.finish(harvest.bindingTable());
    }
    builder.edge(builder.entryIndex, res.entry, 'seq');
    builder.connect(res.exits, builder.exitIndex, 'seq'); // normal fall-off → EXIT
    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] Java buildFunctionCfg skipped a function in ${filePath}: ${String(err)}`);
    return undefined;
  }
}

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

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

export { JAVA_FUNCTION_TYPES };

View on GitHub (pinned to aac7515d2a)

Solutions

  1. Read the ${String(err)} portion of the warning to find the thrown error
  2. Reproduce on the single file and inspect the failing function's node types
  3. Resync grammar and visitor via reinstall, or patch the Java visitor to cover the node type
  4. Re-run analyze --index-only to rebuild the CFG
  5. Accept the skip — only that function lacks a CFG
Defensive patterns

Strategy: fallback

Validate before calling

// prescreen: ERROR nodes from invalid Java are the usual skip trigger
if (tree.rootNode.hasError) fixSourceOrExclude(file);

Try / catch

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

Prevention

When it happens

Trigger: A Java construct inside a method/constructor body the walker does not model: newer switch-expression or pattern-matching shapes, annotation-heavy declarations, or ERROR/MISSING nodes from syntactically broken code, causing an internal invariant to throw during the walk.

Common situations: Vendored tree-sitter-java grammar drift versus the visitor's handled node types; indexing code with syntax errors; generated Java (RPC stubs, builders) with exotic node shapes; very new JDK syntax the visitor predates.

Related errors


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