{"record":{"id":"0a7565d615d1ec3f","repo":"abhigyanpatwari/GitNexus","slug":"cfg-swift-buildfunctioncfg-skipped-a-function-in","errorCode":null,"errorMessage":"[cfg] Swift buildFunctionCfg skipped a function in ${filePath}: ${String(err)}","messagePattern":"\\[cfg\\] Swift buildFunctionCfg skipped a function in (.+?): (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"gitnexus/src/core/ingestion/cfg/visitors/swift.ts","lineNumber":1004,"sourceCode":"\n    const walk = new SwiftCfgWalk(builder, harvest);\n    const res = body\n      ? walk.visitSeq(\n          body.namedChildren.filter((c) => c.type !== 'comment' && c.type !== 'multiline_comment'),\n        )\n      : null;\n\n    builder.edge(builder.entryIndex, res ? res.entry : builder.exitIndex, 'seq');\n    // Normal fall-off threads through the active `defer` chain (LIFO) → EXIT.\n    const normalExits = res ? res.exits : [builder.entryIndex];\n    const afterDefers = walk.finishDefers(normalExits);\n    builder.connect(afterDefers, builder.exitIndex, 'seq');\n    return builder.finish(harvest.bindingTable());\n  } catch (err) {\n    // Never throw out of buildFunctionCfg — a malformed AST shape must skip only\n    // this one function's CFG, never drop the whole file's language group (R4).\n    // eslint-disable-next-line no-console\n    console.warn(`[cfg] Swift buildFunctionCfg skipped a function in ${filePath}: ${String(err)}`);\n    return undefined;\n  }\n}\n\n/**\n * The function's body `statements` node. A `function_declaration` / `init_` /\n * `deinit_declaration` wraps it in a `function_body`; a `lambda_literal` carries\n * the `statements` directly (after an optional `lambda_function_type` + `in`).\n */\nfunction bodyStatementsOf(fnNode: SyntaxNode): SyntaxNode | undefined {\n  const fb =\n    fnNode.childForFieldName('body') ??\n    fnNode.namedChildren.find((c) => c.type === 'function_body');\n  if (fb && fb.type === 'function_body') {\n    return fb.namedChildren.find((c) => c.type === 'statements');\n  }\n  if (fnNode.type === 'lambda_literal') {\n    return fnNode.namedChildren.find((c) => c.type === 'statements');","sourceCodeStart":986,"sourceCodeEnd":1022,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/aac7515d2a8c50a1f8f923c6fb77218b333560d6/gitnexus/src/core/ingestion/cfg/visitors/swift.ts#L986-L1022","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the ${String(err)} portion of the warning for the thrown exception","Reproduce on the single file and inspect bodyStatementsOf's result plus failing nodes","Rebuild the optional swift grammar (reinstall deps; ensure it was not skipped via GITNEXUS_SKIP_OPTIONAL_GRAMMARS) or patch the visitor","Re-run analyze --index-only to rebuild the CFG","Accept the skip — only that function loses its CFG and defer threading"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// prescreen: invalid Swift parses with ERROR nodes\nif (tree.rootNode.hasError) fixSourceOrExclude(file);","typeGuard":null,"tryCatchPattern":"const cfg = visitor.buildFunctionCfg(fn, ctx);\nif (cfg === undefined) continue; // warned skip; defer threading lost for this fn","preventionTips":["Ensure the optional Swift grammar is installed and current when Swift coverage matters","Report result-builder / lambda_literal shapes that fail bodyStatementsOf","Resync grammar and visitor after upgrades","Treat absent CFG as UNKNOWN risk"],"tags":["cfg","tree-sitter","swift","ingestion","graceful-degradation"],"backgroundTag":"tree-sitter-unknown-node-type","analyzedSha":"aac7515d2a8c50a1f8f923c6fb77218b333560d6","analyzedAt":"2026-08-20T23:29:22.980Z","contentChangedAt":"2026-08-20T23:29:22.980Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}