abhigyanpatwari/GitNexus · warning

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

Error message

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

What it means

During indexing GitNexus builds a per-function control-flow graph (CFG) with a Dart tree-sitter visitor. buildFunctionCfg wraps the body walk in a catch-all: any throw from an unexpected or malformed AST shape is logged with console.warn and only that function's CFG is skipped (returns undefined), protecting the file's whole language group ('R4' isolation). Functions covered include function_body nodes preceded by a signature (top-level functions, methods, getters, setters, constructors) and function_expression closures.

Source

Thrown at gitnexus/src/core/ingestion/cfg/visitors/dart.ts:1094

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

    const walk = new DartCfgWalk(builder, harvest);
    const res = block ? walk.visitSeq(block.namedChildren.filter((c) => !isComment(c))) : null;

    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] Dart buildFunctionCfg skipped a function in ${filePath}: ${String(err)}`);
    return undefined;
  }
}

/**
 * Whether a node is a Dart function this visitor builds a CFG for: a
 * `function_body` whose previous sibling is a signature (top-level fn / method /
 * getter / setter / constructor), or a `function_expression` (a closure).
 */
function isFunction(node: SyntaxNode): boolean {
  if (node.type === 'function_expression') return true;
  if (node.type !== 'function_body') return false;
  const prev = node.previousSibling;
  return prev !== null && DART_SIGNATURE_TYPES.has(prev.type);
}

/** The Dart CFG visitor. */
export function createDartCfgVisitor(): CfgVisitor<SyntaxNode> {

View on GitHub (pinned to aac7515d2a)

Solutions

  1. Read the ${String(err)} portion of the warning to identify the thrown exception
  2. Index just the affected file and inspect the tree-sitter node types around the failing function
  3. Align grammar and visitor: reinstall deps (rebuilds/sources vendored grammars) or patch the Dart visitor for the node type
  4. Re-run analyze --index-only to rebuild the CFG
  5. Accept the skip if unfixable — only that function loses its CFG
Defensive patterns

Strategy: fallback

Validate before calling

// prescreen before indexing: reject files whose parse produced errors
if (tree.rootNode.hasError) fixSourceOrExclude(file);

Try / catch

const cfg = visitor.buildFunctionCfg(fn, ctx);
if (cfg === undefined) continue; // warned skip: this function has no CFG

Prevention

When it happens

Trigger: A construct inside a Dart function body the walker does not model: Dart 3 pattern constructs, unusual cascade sections, closure bodies with shapes visitSeq does not expect, or ERROR/MISSING nodes from parsing syntactically broken code, causing an internal throw during the walk.

Common situations: Grammar version drift between vendored tree-sitter-dart and the visitor; indexing code with syntax errors; generated Dart (json_serializable/protobuf output) with node shapes the walker mishandles; skipping optional grammars at install then re-enabling them with a stale build.

Related errors


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