{"record":{"id":"5feb492864cb9301","repo":"apache/beam","slug":"received-unknown-value-type-want-byte-got-t","errorCode":null,"errorMessage":"received unknown value type: want []byte, got %T","messagePattern":"received unknown value type: want \\[\\]byte, got %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/exec/coder.go","lineNumber":313,"sourceCode":"\n\tcase coder.ShardedKey:\n\t\treturn &shardedKeyDecoder{\n\t\t\tkey: MakeElementDecoder(c.Components[0]),\n\t\t}\n\n\tdefault:\n\t\tpanic(fmt.Sprintf(\"Unexpected coder: %v\", c))\n\t}\n}\n\ntype bytesEncoder struct{}\n\nfunc (*bytesEncoder) Encode(val *FullValue, w io.Writer) error {\n\t// Encoding: size (varint) + raw data\n\tvar data []byte\n\tdata, ok := val.Elm.([]byte)\n\tif !ok {\n\t\treturn errors.Errorf(\"received unknown value type: want []byte, got %T\", val.Elm)\n\t}\n\treturn coder.EncodeBytes(data, w)\n}\n\ntype bytesDecoder struct{}\n\nfunc (*bytesDecoder) DecodeTo(r io.Reader, fv *FullValue) error {\n\t// Encoding: size (varint) + raw data\n\tdata, err := coder.DecodeBytes(r)\n\tif err != nil {\n\t\treturn err\n\t}\n\t*fv = FullValue{Elm: data}\n\treturn nil\n}\n\nfunc (d *bytesDecoder) Decode(r io.Reader) (*FullValue, error) {\n\tfv := &FullValue{}","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/exec/coder.go#L295-L331","documentation":"The bytes encoder in the exec package expects a FullValue whose Elm is a []byte. If the element holds any other type, this error is returned instead of silently mis-encoding. It means the element's runtime type doesn't match the coder the pipeline assigned to it.","triggerScenarios":"bytesEncoder.Encode is called with a FullValue whose Elm is, e.g., a string or custom struct instead of []byte — usually a coder/type mismatch between the PCollection's declared type and emitted values.","commonSituations":"Emitting string values into a PCollection declared as []byte; schema inference picking the bytes coder for a differently-typed element; unsafe type assertions bypassed by reflection.","solutions":["Make the DoFn emit []byte: convert with []byte(str) before output.","Fix the PCollection type declaration so the coder matches the element type.","Check beam.Encoded / coder registration so strings use a string coder, not the bytes coder.","Add a type assertion in the DoFn to fail early with a clearer message."],"exampleFix":"// before\nout.Emit(ctx, s) // s is a string into a bytes-coder PCollection\n// after\nout.Emit(ctx, []byte(s))","handlingStrategy":"type-guard","validationCode":"// guard elements before emitting into a bytes-coder PCollection\nfunc assertBytes(v any) ([]byte, error) {\n    b, ok := v.([]byte)\n    if !ok {\n        return nil, fmt.Errorf(\"bytes coder requires []byte, got %T\", v)\n    }\n    return b, nil\n}","typeGuard":"func isByteSlice(v any) bool {\n    _, ok := v.([]byte)\n    return ok\n}","tryCatchPattern":"if err := enc.Encode(fv, w); err != nil {\n    if strings.Contains(err.Error(), \"want []byte\") {\n        return fmt.Errorf(\"element type %T does not match bytes coder: %w\", fv.Elm, err)\n    }\n    return err\n}","preventionTips":["Convert strings/other types to []byte before emitting into bytes-coded PCollections.","Keep the PCollection's declared element type in sync with what DoFns actually emit.","Use beam.Encoded or explicit coder registration deliberately, not accidentally.","Add a quick unit test asserting the emitted type matches the coder."],"tags":["go","apache-beam","encoding","type-mismatch","coder"],"backgroundTag":"type-mismatch","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"}