Skip to content

Commit c41a93e

Browse files
committed
Fix nil pointer panics in explain functions
Add nil checks to explainCreateQuery and explainRenameQuery to handle cases where the parser returns nil AST nodes wrapped in interfaces.
1 parent 0a81a8f commit c41a93e

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

internal/explain/statements.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ func explainInsertQuery(sb *strings.Builder, n *ast.InsertQuery, indent string,
5959
}
6060

6161
func explainCreateQuery(sb *strings.Builder, n *ast.CreateQuery, indent string, depth int) {
62+
if n == nil {
63+
fmt.Fprintf(sb, "%s*ast.CreateQuery\n", indent)
64+
return
65+
}
6266
// Handle special CREATE types
6367
if n.CreateFunction {
6468
children := 2 // identifier + lambda
@@ -344,6 +348,10 @@ func explainDropQuery(sb *strings.Builder, n *ast.DropQuery, indent string, dept
344348
}
345349

346350
func explainRenameQuery(sb *strings.Builder, n *ast.RenameQuery, indent string, depth int) {
351+
if n == nil {
352+
fmt.Fprintf(sb, "%s*ast.RenameQuery\n", indent)
353+
return
354+
}
347355
// Count identifiers: 4 per pair (from_db, from_table, to_db, to_table)
348356
children := len(n.Pairs) * 4
349357
fmt.Fprintf(sb, "%sRename (children %d)\n", indent, children)

0 commit comments

Comments
 (0)