apache/beam · error

bad element

Error message

bad element

What it means

During graph deserialization, decodeType reconstructs reflect.Type values from the protobuf model. For a slice type, the element type is decoded recursively; if that fails the error is wrapped as 'bad element' and contextualized with 'failed to decode type %v, bad element'. This means the slice's element type descriptor in the graph is missing or undecodable.

Solutions

  1. Ensure the submitting SDK version matches the runner's supported graphx version
  2. Check that the Type_SLICE message has a non-nil Element in the graph proto
  3. Re-encode the pipeline with a current SDK so the element type is present
  4. Inspect the wrapped inner error for the root undecodable type
Defensive patterns

Strategy: try-catch

Type guard

if t.GetKind() == v1pb.Type_SLICE && t.GetElement() == nil {
	return errors.New("slice type has no element descriptor")
}

Try / catch

typ, err := graphx.DecodeType(pbType)
if err != nil {
	for unwrapped := err; unwrapped != nil; {
		log.Printf("decode failure: %v", unwrapped)
		unwrapped = errors.Unwrap(unwrapped)
	}
	return fmt.Errorf("graph decode failed (version skew?): %w", err)
}

Prevention

When it happens

Trigger: Decoding a model graph produced by a different Beam version where the element Type message was omitted or written by newer encode logic; corrupted or truncated Element field in v1pb.Type_SLICE.

Common situations: Version skew between job-submitter SDK and runner when a runner deserializes the graph; hand-edited or synthetic graph protos; nil Element pointer in the Type message.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

Thrown at sdks/go/pkg/beam/core/runtime/graphx/serialize.go:600

	case v1pb.Type_UINT8:
		return reflectx.Uint8, nil
	case v1pb.Type_UINT16:
		return reflectx.Uint16, nil
	case v1pb.Type_UINT32:
		return reflectx.Uint32, nil
	case v1pb.Type_UINT64:
		return reflectx.Uint64, nil
	case v1pb.Type_FLOAT32:
		return reflectx.Float32, nil
	case v1pb.Type_FLOAT64:
		return reflectx.Float64, nil
	case v1pb.Type_STRING:
		return reflectx.String, nil

	case v1pb.Type_SLICE:
		elm, err := decodeType(t.GetElement())
		if err != nil {
			wrapped := errors.Wrap(err, "bad element")
			return nil, errors.WithContextf(wrapped, "failed to decode type %v, bad element", t)
		}
		return reflect.SliceOf(elm), nil

	case v1pb.Type_STRUCT:
		var fields []reflect.StructField
		for _, f := range t.Fields {
			fType, err := decodeType(f.Type)
			if err != nil {
				wrapped := errors.Wrap(err, "bad field type")
				return nil, errors.WithContextf(wrapped, "failed to decode type %v, bad field type", t)
			}

			field := reflect.StructField{
				Name:      f.GetName(),
				PkgPath:   f.GetPkgPath(),
				Type:      fType,
				Tag:       reflect.StructTag(f.GetTag()),

View on GitHub (pinned to 12126d8942)