apache/beam · error

failed to marshal window coder

Error message

failed to marshal window coder %v

What it means

Wraps failure of AddMulti when marshalling the element components of a coder.WindowedValue coder (the first wrap call of two in that case). The windowed-value wrapper needs its value components serialized before the window coder; a failing component produces this error.

Solutions

  1. Inspect the wrapped error for the failing component coder
  2. Register the element types with beam.RegisterType before beam.Init
  3. Verify windowing setup only uses supported window kinds
  4. Upgrade the SDK if the component kind is new
Defensive patterns

Strategy: try-catch

Try / catch

// Distinguish the two wrapped stages by unwrapping
if err != nil && strings.Contains(err.Error(), "failed to marshal window coder") {
    log.Printf("windowed value component failure: %v", errors.Unwrap(err))
}

Prevention

When it happens

Trigger: CoderBuilder.Add on a coder.WindowedValue whose element components fail AddMulti.

Common situations: Windowed PCollections over unregistered custom types; failures originating in nested component coders.

Understand the failure class

Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.

Related errors


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

Appendix: source

Thrown at sdks/go/pkg/beam/core/runtime/graphx/coder.go:520

		// SDKs always provide iterableCoder to runners, but can receive StateBackedIterables in return.
		stream := b.internBuiltInCoder(urnIterableCoder, value)
		return b.internBuiltInCoder(urnKVCoder, comp[0], stream), nil

	case coder.ShardedKey:
		comp, err := b.AddMulti(c.Components)
		if err != nil {
			return "", errors.Wrapf(err, "failed to marshal ShardedKey coder %v", c)
		}
		if len(comp) != 1 {
			return "", errors.Errorf("ShardedKey coder requires exactly 1 component (key), got %d", len(comp))
		}
		return b.internBuiltInCoder(urnShardedKeyCoder, comp...), nil

	case coder.WindowedValue:
		comp := []string{}
		if ids, err := b.AddMulti(c.Components); err != nil {
			return "", errors.Wrapf(err, "failed to marshal window coder %v", c)
		} else {
			comp = append(comp, ids...)
		}
		if id, err := b.AddWindowCoder(c.Window); err != nil {
			return "", errors.Wrapf(err, "failed to marshal window coder %v", c)
		} else {
			comp = append(comp, id)
		}
		return b.internBuiltInCoder(urnWindowedValueCoder, comp...), nil

	case coder.Bytes:
		// TODO(herohde) 6/27/2017: add length-prefix and not assume nested by context?
		return b.internBuiltInCoder(urnBytesCoder), nil

	case coder.Bool:
		return b.internBuiltInCoder(urnBoolCoder), nil

	case coder.VarInt:

View on GitHub (pinned to 12126d8942)