vitessio/vitess · error

input is not a slice

Error message

input is not a slice

What it means

Error in sqlparser's tracked_buffer (used for AST formatting/generation): a value expected to be a slice (list of child nodes) is not a slice, so it cannot be walked. Thrown at go/vt/sqlparser/tracked_buffer.go:271.

Source

Thrown at go/vt/sqlparser/tracked_buffer.go:271

		buf.formatter(expr)
		prefix = ", "
	}
}

func (buf *TrackedBuffer) formatNodes(input any) {
	switch nodes := input.(type) {
	case []Expr:
		buf.formatExprs(nodes)
		return
	}

	// SLOW PATH! Add specific cases above to avoid reflection.

	// Check if the input is a slice
	val := reflect.ValueOf(input)
	if val.Kind() != reflect.Slice {
		// Handle the error or return if input is not a slice
		panic("input is not a slice")
	}

	// Iterate over the slice elements
	for i := 0; i < val.Len(); i++ {
		elem := val.Index(i).Interface()

		// Assert each element implements SQLNode
		node, ok := elem.(SQLNode)
		if !ok {
			// Handle the error or skip non-SQLNode elements
			panic("element does not implement SQLNode")
		}

		// Now `node` is of type SQLNode
		// You can call methods or use it as a SQLNode here
		buf.Myprintf("%v", node)
	}
}

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Wrap the node in a slice: buf.Myprintf("%n", []SQLNode{node})
  2. Or use %v for a single SQLNode value
  3. Verify with a ToString() test for the affected node

Example fix

// before
buf.Myprintf("%n", node.Exprs[0])
// after
buf.Myprintf("%n", node.Exprs)
Defensive patterns

Strategy: validation

Validate before calling

rv := reflect.ValueOf(v)
if rv.Kind() != reflect.Slice {
    return fmt.Errorf("%%n requires a slice, got %T", v)
}

Type guard

func isSQLNodeSlice(v any) bool {
    rv := reflect.ValueOf(v)
    if rv.Kind() != reflect.Slice {
        return false
    }
    for i := 0; i < rv.Len(); i++ {
        if _, ok := rv.Index(i).Interface().(SQLNode); !ok {
            return false
        }
    }
    return true
}

Prevention

When it happens

Trigger: An AST Format method passes a single SQLNode (not a slice) with the %n verb, e.g. buf.Myprintf("%n", singleNode) instead of %v.

Common situations: Confusing %n (slice-of-nodes) with %v (single node) when writing or editing Format methods for nodes containing lists (e.g. TableExprs, SelectExprs).

Related errors


AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01). Data as JSON: /api/errors/5b0545a5a9e3705a. Report an issue: GitHub.