Debugging with Graph Queries
Track down bugs using the code knowledge graph
Use noodlbox's graph queries to trace bugs, find root causes, and understand error propagation.
Scenario
You have a bug to fix and need to:
- Find where the error occurs
- Trace the call stack
- Understand data flow
- Identify the root cause
Tools & Resources
- Context Search - Find error-related code
- Cypher Query - Trace relationships
- Process Trace - Follow execution
- Database Schema - Understand structure
Debugging Workflows
Workflow 1: Error Message
You have an error message, find the source:
{
"repository": "my-app",
"q": "UserNotFoundError database query",
"task_context": "Debugging user not found error",
"current_goal": "Find where error is thrown",
"search_intention": "Locate error source code"
}Then trace callers:
MATCH (caller:CODE_SYMBOL)-[:CALLS]->(error:CODE_SYMBOL)
WHERE error.name CONTAINS "UserNotFoundError"
RETURN caller.name, caller.file_pathWorkflow 2: Unexpected Behavior
Function returns wrong value:
- Find the function:
MATCH (f:CODE_SYMBOL {name: "calculateTotal"})
RETURN f.file_path, f.line_number- Find what it calls:
MATCH (f:CODE_SYMBOL {name: "calculateTotal"})-[:CALLS]->(dep:CODE_SYMBOL)
RETURN dep.name, dep.file_path
ORDER BY dep.name- Find who calls it:
MATCH (caller:CODE_SYMBOL)-[:CALLS]->(f:CODE_SYMBOL {name: "calculateTotal"})
RETURN caller.name, caller.file_pathWorkflow 3: Trace Data Flow
Track variable through the system:
// Find all functions handling "userId"
MATCH (s:CODE_SYMBOL)
WHERE s.name CONTAINS "userId" OR s.name CONTAINS "UserId"
RETURN s.name, s.symbol_type, s.file_pathThen trace the call chain:
MATCH path = (start:CODE_SYMBOL)-[:CALLS*1..5]->(end:CODE_SYMBOL)
WHERE start.name = "handleRequest"
AND end.name CONTAINS "userId"
RETURN path
LIMIT 10Example: Debugging a Null Pointer
Problem
Getting "Cannot read property 'id' of null" in production.
Step 1: Find the Error Location
{
"repository": "api-server",
"q": "Cannot read property id",
"task_context": "Debugging null pointer error",
"current_goal": "Find error location",
"search_intention": "Locate crash site"
}Result: getUserProfile in src/users/profile.ts:89
Step 2: Understand the Function
MATCH (f:CODE_SYMBOL {name: "getUserProfile"})
MATCH (f)-[:CALLS]->(dep:CODE_SYMBOL)
RETURN f.file_path, dep.nameCalls: getUser, formatProfile, validateAccess
Step 3: Find Where User Might Be Null
MATCH (f:CODE_SYMBOL {name: "getUser"})
MATCH (f)-[:CALLS]->(db:CODE_SYMBOL)
WHERE db.name CONTAINS "query" OR db.name CONTAINS "find"
RETURN db.name, db.file_pathStep 4: Trace Back to Entry Point
MATCH path = (entry:CODE_SYMBOL)-[:CALLS*]->(f:CODE_SYMBOL {name: "getUserProfile"})
WHERE entry.symbol_type = "Function"
AND entry.name CONTAINS "handler" OR entry.name CONTAINS "route"
RETURN path
LIMIT 5Step 5: Check Error Handling
MATCH (f:CODE_SYMBOL)
WHERE f.name CONTAINS "error" OR f.name CONTAINS "catch"
AND f.file_path CONTAINS "users"
RETURN f.name, f.file_pathDebugging Patterns
Pattern 1: Find All Error Handlers
MATCH (s:CODE_SYMBOL)
WHERE s.name CONTAINS "error"
OR s.name CONTAINS "catch"
OR s.name CONTAINS "handle"
RETURN s.name, s.file_path, s.symbol_type
ORDER BY s.file_pathPattern 2: Trace Exception Propagation
MATCH path = (throw:CODE_SYMBOL)-[:CALLS*]-> (catch:CODE_SYMBOL)
WHERE throw.name CONTAINS "throw"
AND catch.name CONTAINS "catch"
RETURN path
LIMIT 10Pattern 3: Find Validation Functions
MATCH (v:CODE_SYMBOL)
WHERE v.name CONTAINS "validate"
OR v.name CONTAINS "check"
OR v.name CONTAINS "verify"
RETURN v.name, v.file_path
ORDER BY v.nameTips
Start from the Error
- Search for the error message
- Find the throwing function
- Trace callers backward
- Identify missing validations
Use Processes
If the bug happens during a specific flow:
GET map://my-appFind the process, then trace it:
GET map://my-app/process/{process-id}Check Cross-Community Calls
Bugs often occur at boundaries:
GET map://my-appLook at cross_flows with high call counts.
Related
- Cypher Query Tool - Trace relationships
- Context Search - Find error code
- Process Trace - Follow execution