{"record":{"id":"f790b37bc9bd1f3c","repo":"apache/beam","slug":"registershardedkeytype-bad-dec-for-v-v","errorCode":null,"errorMessage":"RegisterShardedKeyType: bad dec for %v: %v","messagePattern":"RegisterShardedKeyType: bad dec for (.+?): (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/transforms/batch/batch.go","lineNumber":153,"sourceCode":"\t// the correct enc/dec for each ShardedKey[K].\n\tencName := fmt.Sprintf(\"batch.encShardedKey[%v]\", keyT)\n\tdecName := fmt.Sprintf(\"batch.decShardedKey[%v]\", keyT)\n\n\tencFn := reflectx.MakeFuncWithName(encName, enc)\n\tdecFn := reflectx.MakeFuncWithName(decName, dec)\n\n\t// Register in the runtime cache under the qualified name so\n\t// ResolveFunction finds them at deserialization time.\n\truntime.RegisterFunctionWithName(encName, enc)\n\truntime.RegisterFunctionWithName(decName, dec)\n\n\tencWrapped, err := funcx.New(encFn)\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"RegisterShardedKeyType: bad enc for %v: %v\", skT, err))\n\t}\n\tdecWrapped, err := funcx.New(decFn)\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"RegisterShardedKeyType: bad dec for %v: %v\", skT, err))\n\t}\n\n\tbeamcoder.RegisterDeterministicCoderWithFuncs(skT, encWrapped, decWrapped)\n}\n\n// Params configures GroupIntoBatches and\n// GroupIntoBatchesWithShardedKey.\n//\n// At least one of BatchSize or BatchSizeBytes must be > 0.\ntype Params struct {\n\t// BatchSize is the target maximum number of elements per batch. A\n\t// batch is emitted as soon as it holds BatchSize elements. Zero\n\t// disables the count-based trigger.\n\tBatchSize int64\n\n\t// BatchSizeBytes is the target maximum cumulative byte size per\n\t// batch. A batch is emitted as soon as adding another element\n\t// would exceed BatchSizeBytes. Zero disables the byte-based","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/transforms/batch/batch.go#L135-L171","documentation":"The counterpart of the encoder wrap failure: RegisterShardedKeyType panics when funcx.New fails to wrap the decoder closure decFn. The decoder's signature must be acceptable to funcx so the runtime can locate and call it at deserialization time.","triggerScenarios":"Calling RegisterShardedKeyType[K] where decFn's signature (func([]byte) ShardedKey[K]) cannot be wrapped by funcx.New — same root causes as the encoder wrap failure: SDK/toolchain mismatch or generic closure issues.","commonSituations":"Beam Go SDK version drift; Go compiler changes affecting generic closure symbols; registering a dec that was edited to a non-standard signature.","solutions":["Align the Beam Go SDK version with the one where funcx.New supports these closures.","Restore/verify decFn's canonical signature func([]byte) ShardedKey[K].","Inspect the funcx.New error message to identify the exact signature mismatch."],"exampleFix":"// before\nfunc badDec(b []byte) (ShardedKey[K], error) { ... } // non-canonical signature\n// after\nfunc dec(b []byte) ShardedKey[K] { ... } // canonical: wraps errors via panic internally","handlingStrategy":"validation","validationCode":"if _, err := funcx.New(decFn); err != nil {\n    log.Fatalf(\"funcx cannot wrap dec for %v: %v\", reflect.TypeOf(new(K)), err)\n}","typeGuard":null,"tryCatchPattern":"func init() {\n    defer func() {\n        if r := recover(); r != nil {\n            log.Fatalf(\"RegisterShardedKeyType (dec) init failed: %v\", r)\n        }\n    }()\n    batch.RegisterShardedKeyType[MyKey]()\n}","preventionTips":["Keep decFn's signature exactly func([]byte) ShardedKey[K]","Don't hand-edit generated enc/dec closures","Pin SDK versions in go.mod and CI"],"tags":["go","beam","reflection","funcx","init"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}