apache/beam · error

RegisterShardedKeyType: bad dec for %v: %v

Error message

RegisterShardedKeyType: bad dec for %v: %v

What it means

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.

Source

Thrown at sdks/go/pkg/beam/transforms/batch/batch.go:153

	// the correct enc/dec for each ShardedKey[K].
	encName := fmt.Sprintf("batch.encShardedKey[%v]", keyT)
	decName := fmt.Sprintf("batch.decShardedKey[%v]", keyT)

	encFn := reflectx.MakeFuncWithName(encName, enc)
	decFn := reflectx.MakeFuncWithName(decName, dec)

	// Register in the runtime cache under the qualified name so
	// ResolveFunction finds them at deserialization time.
	runtime.RegisterFunctionWithName(encName, enc)
	runtime.RegisterFunctionWithName(decName, dec)

	encWrapped, err := funcx.New(encFn)
	if err != nil {
		panic(fmt.Sprintf("RegisterShardedKeyType: bad enc for %v: %v", skT, err))
	}
	decWrapped, err := funcx.New(decFn)
	if err != nil {
		panic(fmt.Sprintf("RegisterShardedKeyType: bad dec for %v: %v", skT, err))
	}

	beamcoder.RegisterDeterministicCoderWithFuncs(skT, encWrapped, decWrapped)
}

// Params configures GroupIntoBatches and
// GroupIntoBatchesWithShardedKey.
//
// At least one of BatchSize or BatchSizeBytes must be > 0.
type Params struct {
	// BatchSize is the target maximum number of elements per batch. A
	// batch is emitted as soon as it holds BatchSize elements. Zero
	// disables the count-based trigger.
	BatchSize int64

	// BatchSizeBytes is the target maximum cumulative byte size per
	// batch. A batch is emitted as soon as adding another element
	// would exceed BatchSizeBytes. Zero disables the byte-based

View on GitHub (pinned to 12126d8942)

Solutions

  1. Align the Beam Go SDK version with the one where funcx.New supports these closures.
  2. Restore/verify decFn's canonical signature func([]byte) ShardedKey[K].
  3. Inspect the funcx.New error message to identify the exact signature mismatch.

Example fix

// before
func badDec(b []byte) (ShardedKey[K], error) { ... } // non-canonical signature
// after
func dec(b []byte) ShardedKey[K] { ... } // canonical: wraps errors via panic internally
Defensive patterns

Strategy: validation

Validate before calling

if _, err := funcx.New(decFn); err != nil {
    log.Fatalf("funcx cannot wrap dec for %v: %v", reflect.TypeOf(new(K)), err)
}

Try / catch

func init() {
    defer func() {
        if r := recover(); r != nil {
            log.Fatalf("RegisterShardedKeyType (dec) init failed: %v", r)
        }
    }()
    batch.RegisterShardedKeyType[MyKey]()
}

Prevention

When it happens

Trigger: 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.

Common situations: Beam Go SDK version drift; Go compiler changes affecting generic closure symbols; registering a dec that was edited to a non-standard signature.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/f790b37bc9bd1f3c. Report an issue: GitHub.