{"record":{"id":"200faea6b1b90f25","repo":"apache/beam","slug":"batch-unknown-sizer-kind-d","errorCode":null,"errorMessage":"batch: unknown sizer kind %d","messagePattern":"batch: unknown sizer kind (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/transforms/batch/batch.go","lineNumber":482,"sourceCode":"\tif setBool {\n\t\tfn.Buffering.Clear(tp)\n\t\tif err := fn.TimerSet.Clear(sp); err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t}\n}\n\nfunc sizeOf(kind int32, v any) int64 {\n\tswitch kind {\n\tcase sizerNone:\n\t\treturn 0\n\tcase sizerPrimitive:\n\t\tif size, ok := defaultElementByteSize(v); ok {\n\t\t\treturn size\n\t\t}\n\t\tpanic(fmt.Sprintf(\"batch: sizerPrimitive cannot size value of type %T\", v))\n\tdefault:\n\t\tpanic(fmt.Sprintf(\"batch: unknown sizer kind %d\", kind))\n\t}\n}\n\n// wrapShardedKeyFn maps KV<K, V> → KV<ShardedKey[K], V>.\ntype wrapShardedKeyFn[K any] struct{}\n\nfunc (*wrapShardedKeyFn[K]) ProcessElement(\n\tkey K, value typex.V, emit func(ShardedKey[K], typex.V),\n) {\n\temit(ShardedKey[K]{Key: key, ShardID: makeShardID()}, value)\n}\n\nvar (\n\tworkerUUIDOnce sync.Once\n\tworkerUUIDVal  [16]byte\n\tshardCounter   atomic.Uint64\n)\n","sourceCodeStart":464,"sourceCodeEnd":500,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/transforms/batch/batch.go#L464-L500","documentation":"sizeOf falls through to its default branch when the configured sizer kind is not one of sizerNone/sizerPrimitive/sizerCustom. This is an internal invariant: the Sizer enum field was set to an undefined value, so the transform cannot dispatch and panics.","triggerScenarios":"Constructing the batch DoFn with a Sizer field set to an out-of-range integer (not one of the exported sizer* constants) and then processing elements via ProcessElement.","commonSituations":"Hand-rolled struct literals copying examples with a numeric Sizer field, or upstream code changes that renumbered the sizer constants.","solutions":["Use only the exported sizer constants (sizerNone/sizerPrimitive/sizerCustom equivalents) when constructing the DoFn.","Add validation at DoFn construction time to reject unknown sizer kinds early.","Update to the latest SDK where the sizer API may be typed to prevent invalid values.","Audit code that sets the sizer field numerically and replace with named constants."],"exampleFix":"// before\nfn := batchFn[K, V]{Sizer: 7}\n// after\nfn := batchFn[K, V]{Sizer: sizerPrimitive}","handlingStrategy":"validation","validationCode":"// Validate the sizer kind before constructing the DoFn\nfunc validSizer(k int32) bool {\n\treturn k == sizerNone || k == sizerPrimitive || k == sizerCustom\n}\nif !validSizer(mySizerKind) {\n\tpanic(fmt.Sprintf(\"invalid sizer kind %d\", mySizerKind))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use named sizer constants, never raw ints","Add construction-time validation of sizer kind","Rely on typed enums if migrating to a newer SDK"],"tags":["go","apache-beam","invalid-enum","panic"],"backgroundTag":"invalid-enum-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}