vitessio/vitess · error

unknown type %T %v

Error message

unknown type %T %v

What it means

asthelpergen's printableTypeName converts go/types values into the human-readable type names used in generated helper method names and comments. It handles Named, Pointer, Slice, Basic, and Interface types; anything else (map, struct literal, chan, tuple, etc.) hits the default case and panics. It is a dev-time codegen failure.

Source

Thrown at go/tools/asthelpergen/asthelpergen.go:445

var noQualifier = func(*types.Package) string { return "" }

// printableTypeName returns a string that can be used as a valid golang identifier
func printableTypeName(t types.Type) string {
	switch t := t.(type) {
	case *types.Alias:
		return printableTypeName(types.Unalias(t))
	case *types.Pointer:
		return "RefOf" + printableTypeName(t.Elem())
	case *types.Slice:
		return "SliceOf" + printableTypeName(t.Elem())
	case *types.Named:
		return t.Obj().Name()
	case *types.Basic:
		return textutil.Title(t.Name())
	case *types.Interface:
		return t.String()
	default:
		panic(fmt.Sprintf("unknown type %T %v", t, t))
	}
}

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Add a case for the offending *types.Type kind in printableTypeName (go/tools/asthelpergen/asthelpergen.go) returning a sensible printable name
  2. Simplify the input type so it only contains supported kinds (named, pointer, slice, basic, interface)
  3. Check the type queue printed in the panic message (%T %v) to see exactly which kind leaked in and where from

Example fix

// before (helpergen input)
type Foo struct { M map[string]string }
// after
type Bar struct { M string } // or add a *types.Map case to printableTypeName
Defensive patterns

Strategy: type-guard

Validate before calling

// Check the type kind before queuing it in asthelpergen
switch t.Underlying().(type) {
case *types.Named, *types.Pointer, *types.Slice, *types.Basic, *types.Interface:
    // ok
default:
    return fmt.Errorf("asthelpergen: unsupported type %s", t)
}

Type guard

func supportedForHelperGen(t types.Type) bool {
    switch t.(type) {
    case *types.Named, *types.Pointer, *types.Slice, *types.Basic, *types.Interface:
        return true
    }
    return false
}

Prevention

When it happens

Trigger: Running asthelpergen over a type graph that includes a types.Type kind outside the known set — e.g. a *types.Map, *types.Struct, *types.Chan or *types.Signature reachable from a queued type during processTypeQueue/processTypeWithGenerators, or via readValueOfType/structMethod/sliceMethod recursion.

Common situations: A developer adds a new AST helper for a type containing a map or struct field, or a generics instantiation that surfaces an unsupported type kind, then runs make codegen.

Related errors


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