vitessio/vitess · error

unexepcted TrackedBuffer type %T

Error message

unexepcted TrackedBuffer type %T

What it means

The %d (and %u) verb in astPrintf only accepts signed/unsigned integer types (int types, uint, uint64, uintptr, etc.). Any other value type triggers this panic (note the pre-existing typo 'unexepcted'). It is a developer-facing invariant failure inside AST Format implementations.

Source

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

				buf.WriteInt(int64(v))
			case int32:
				buf.WriteInt(int64(v))
			case int64:
				buf.WriteInt(v)
			case uint:
				buf.WriteUint(uint64(v))
			case uint8:
				buf.WriteUint(uint64(v))
			case uint16:
				buf.WriteUint(uint64(v))
			case uint32:
				buf.WriteUint(uint64(v))
			case uint64:
				buf.WriteUint(v)
			case uintptr:
				buf.WriteUint(uint64(v))
			default:
				panic(fmt.Sprintf("unexepcted TrackedBuffer type %T", v))
			}
		case 'a':
			buf.WriteArg("", values[fieldnum].(string))
		case 'n':
			// used for printing slices of SQLNodes
			value := values[fieldnum]
			buf.formatNodes(value)
		default:
			panic("unexpected format: " + string(format[i-1:i+1]))
		}
		fieldnum++
		i++
	}
}

func (buf *TrackedBuffer) formatExprs(exprs []Expr) {
	var prefix string
	for _, expr := range exprs {

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Pass an integer value to %d, casting if necessary (e.g. uint64(v))
  2. Use %s/%v for string or node values as appropriate
  3. Fix the surrounding Format method and re-run sqlparser AST printing tests

Example fix

// before
buf.Myprintf("%d", t.Name)
// after
buf.Myprintf("%d", t.Count)
Defensive patterns

Strategy: validation

Validate before calling

switch v := value.(type) {
case int, int64, uint, uint64:
    buf.Myprintf("%d", v)
default:
    return fmt.Errorf("%%d requires integer, got %T", v)
}

Try / catch

defer func() {
    if r := recover(); r != nil {
        t.Fatalf("AST formatting panicked (check %%d argument type): %v", r)
    }
}()

Prevention

When it happens

Trigger: An AST Format method calls buf.Myprintf("%d", v) with a string, SQLNode, float, or other non-integer value.

Common situations: Refactoring an AST field from an integer type to string or vice versa without updating Format; typos passing the wrong struct field for the %d verb.

Related errors


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