abhigyanpatwari/GitNexus · warning

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

Error message

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

What it means

During indexing GitNexus builds a per-function control-flow graph (CFG) with a Rust tree-sitter visitor (RUST_FUNCTION_TYPES covers functions and closures). buildFunctionCfg wraps the body walk (visitSeq over namedChildren filtered by isNotComment) in a catch-all: any throw from an unexpected AST shape is logged with console.warn and only that function/closure's CFG is skipped (returns undefined), protecting the file's language group ('R4' isolation).

Source

Thrown at gitnexus/src/core/ingestion/cfg/visitors/rust.ts:715

      const res = walk.visitStmt(body);
      builder.edge(builder.entryIndex, res ? res.entry : builder.exitIndex, 'seq');
      builder.connect(res ? res.exits : [builder.entryIndex], builder.exitIndex, 'seq');
      return builder.finish(harvest.bindingTable());
    }

    const res = walk.visitSeq(body.namedChildren.filter(isNotComment));
    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] Rust buildFunctionCfg skipped a function in ${filePath}: ${String(err)}`);
    return undefined;
  }
}

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

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

export { RUST_FUNCTION_TYPES };

View on GitHub (pinned to aac7515d2a)

Solutions

  1. Read the ${String(err)} portion of the warning for the exact exception
  2. Index just the affected file and inspect the macro/expression node shapes
  3. Resync grammar and visitor via reinstall, or patch the Rust visitor for the shape
  4. Re-run analyze --index-only to rebuild the CFG
  5. Accept the skip — only that function's CFG is absent
Defensive patterns

Strategy: fallback

Validate before calling

// prescreen: macro soup and invalid Rust parse with ERROR nodes
if (tree.rootNode.hasError) fixSourceOrExclude(file);

Try / catch

const cfg = visitor.buildFunctionCfg(fn, ctx);
if (cfg === undefined) continue; // warned skip: fn/closure without CFG

Prevention

When it happens

Trigger: A Rust construct the walker does not model: macro-invocation bodies (macro_rules!/derive-generated shapes), complex match arms, async/await chains, or ERROR/MISSING nodes from syntactically invalid Rust, causing a throw during the walk.

Common situations: Indexing macro-heavy codebases (embedded SQL, serde derives) whose token trees the walker mishandles; grammar drift in the Rust grammar; files with syntax errors; generated Rust (bindgen output, cargo expand artifacts).

Related errors


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