apache/beam · warning
invalid Class value: %v
Error message
invalid Class value: %v
What it means
Class.String() panics when the Class value does not match any known class (Booleans, Integer, Decimal, Float, Byte, String, Universal, Container, Composite). Class is an internal enum of typex type classifications, so receiving this panic means a Class value outside the defined enum range was constructed, e.g. via an unsafe conversion from an integer.
Source
Thrown at sdks/go/pkg/beam/core/typex/class.go:64
// Composite type: KV, CoGBk, WindowedValue. Beam-generic types
// that cannot be represented as a single reflect.Type.
Composite
)
func (c Class) String() string {
switch c {
case Invalid:
return "Invalid"
case Concrete:
return "Concrete"
case Universal:
return "Universal"
case Container:
return "Container"
case Composite:
return "Composite"
default:
panic(fmt.Sprintf("invalid Class value: %v", int(c)))
}
}
// TODO(herohde) 5/16/2017: maybe we should add more classes, so that every
// reasonable type (such as error) is not Invalid, even though it is not
// valid in FullType. "Special", say? Right now, a valid DoFn signature may
// have "Invalid" parameter types, which might be confusing. Or maybe rename
// as DataClass to make the narrower scope clearer?
// ClassOf returns the class of a given type. The class is Invalid, if the
// type is not suitable as data.
func ClassOf(t reflect.Type) Class {
switch {
case IsUniversal(t):
return Universal
case IsComposite(t):
return Composite
case IsContainer(t): // overrules IsConcreteView on GitHub (pinned to 12126d8942)
Solutions
- Inspect how the invalid Class value was created; only use the exported Class constants (typex.Booleans, typex.Container, etc.).
- Never cast raw integers to typex.Class; derive classes via typex.New(t) from reflect.Type values.
- If hit inside the SDK after an upgrade, report/patch: a new Class variant was likely added without updating String().
Example fix
// before c := typex.Class(99) fmt.Println(c.String()) // panics // after var c typex.Class = typex.Container fmt.Println(c.String())
Defensive patterns
Strategy: type-guard
Validate before calling
if c < typex.Booleans || c > typex.Composite { return fmt.Errorf("invalid Class: %d", int(c)) } Type guard
func isValidClass(c typex.Class) bool {
switch c {
case typex.Booleans, typex.Integer, typex.Decimal, typex.Float, typex.Byte, typex.String, typex.Universal, typex.Container, typex.Composite:
return true
}
return false
} Try / catch
defer func() {
if r := recover(); r != nil {
log.Printf("typex Class panic: %v", r)
}
}() Prevention
- Only use exported typex.Class constants; never cast integers to Class.
- Derive types via typex.New from reflect.Type rather than assembling classes manually.
When it happens
Trigger: Calling String() on a Class produced by an out-of-range int conversion (e.g. typex.Class(99)); normally only reachable through misuse of internal typex APIs, not through public Beam pipeline construction.
Common situations: Custom code that builds FullType trees by hand; test harnesses or code generators constructing Class values numerically; SDK-internal bugs after adding a new class without updating String().
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Unexpected aggregate type: %v
- Invalid number of components for KV: %v, %v
- Invalid to nest composite composites inside KV: %v, %v
- Invalid number of components for WindowedValue
- Invalid to nest WindowedValue
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/3cfefeb1ea2e3a17.
Report an issue: GitHub.