Skip to content

fix: Prevent FK constraint failure from nodes with empty names#62

Merged
colbymchenry merged 1 commit intomainfrom
fix/fk-constraint-empty-names
Mar 18, 2026
Merged

fix: Prevent FK constraint failure from nodes with empty names#62
colbymchenry merged 1 commit intomainfrom
fix/fk-constraint-empty-names

Conversation

@colbymchenry
Copy link
Copy Markdown
Owner

Summary

Fixes #42FOREIGN KEY constraint failed when indexing C/C++ header files.

Root cause: Tree-sitter can produce function nodes with empty names from complex C/C++ declarators (e.g. macro-generated declarations in .h files). These nodes were silently skipped by insertNode() validation, but their containment edges were still inserted into the database — causing a FK violation since the target node didn't exist.

Two-layer fix:

  • Extraction layer: createNode() now returns null for empty names, preventing the node and its containment edges from ever being created. All 7 callers that use the return value handle the null case.
  • Storage layer (safety net): storeExtractionResult() now filters edges and unresolved references to only include those referencing nodes that passed validation, preventing any future FK violations from similar edge cases.

Test plan

Fixes #42 — tree-sitter can produce nodes with empty names (e.g. from
complex C/C++ declarators in header files). These nodes were silently
skipped at DB insert time, but their containment edges were still
inserted, causing a FOREIGN KEY constraint violation that crashed
indexing.

Two-layer fix:
- createNode() now returns null for empty names, preventing the node
  and its edges from ever being created (Option A)
- storeExtractionResult() filters edges and unresolved refs to only
  reference nodes that passed validation, as a safety net (Option B)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CodeGraph v0.6.2: FOREIGN KEY constraint failed

1 participant