abhigyanpatwari/GitNexus · warning

[cfg] Swift buildFunctionCfg skipped a function in ${filePat

Error message

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

What it means

During indexing GitNexus builds a per-function control-flow graph (CFG) with a Swift tree-sitter visitor. buildFunctionCfg wraps the walk — including LIFO defer-chain threading via walk.finishDefers, and bodies located by bodyStatementsOf (a function_body wrapper for function_declaration/init_/deinit, or statements carried directly by a lambda_literal) — in a catch-all: any throw 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/swift.ts:1004

    const walk = new SwiftCfgWalk(builder, harvest);
    const res = body
      ? walk.visitSeq(
          body.namedChildren.filter((c) => c.type !== 'comment' && c.type !== 'multiline_comment'),
        )
      : null;

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

/**
 * The function's body `statements` node. A `function_declaration` / `init_` /
 * `deinit_declaration` wraps it in a `function_body`; a `lambda_literal` carries
 * the `statements` directly (after an optional `lambda_function_type` + `in`).
 */
function bodyStatementsOf(fnNode: SyntaxNode): SyntaxNode | undefined {
  const fb =
    fnNode.childForFieldName('body') ??
    fnNode.namedChildren.find((c) => c.type === 'function_body');
  if (fb && fb.type === 'function_body') {
    return fb.namedChildren.find((c) => c.type === 'statements');
  }
  if (fnNode.type === 'lambda_literal') {
    return fnNode.namedChildren.find((c) => c.type === 'statements');

View on GitHub (pinned to aac7515d2a)

Solutions

  1. Read the ${String(err)} portion of the warning for the thrown exception
  2. Reproduce on the single file and inspect bodyStatementsOf's result plus failing nodes
  3. Rebuild the optional swift grammar (reinstall deps; ensure it was not skipped via GITNEXUS_SKIP_OPTIONAL_GRAMMARS) or patch the visitor
  4. Re-run analyze --index-only to rebuild the CFG
  5. Accept the skip — only that function loses its CFG and defer threading
Defensive patterns

Strategy: fallback

Validate before calling

// prescreen: invalid Swift parses with ERROR nodes
if (tree.rootNode.hasError) fixSourceOrExclude(file);

Try / catch

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

Prevention

When it happens

Trigger: A Swift construct the walker does not model: result-builder transformed bodies, property-wrapper or closure shapes where childForFieldName('body') returns an unexpected node, odd defer placements breaking finishDefers, or ERROR/MISSING nodes from invalid Swift source.

Common situations: Swift is an optional vendored grammar — a stale or source-built copy drifts from the visitor; indexing SwiftUI code dense with result builders; files with syntax errors; newer Swift syntax the walker predates.

Related errors


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