{"record":{"id":"922353cfa2c64472","repo":"apache/beam","slug":"value-v-not-encodable-with-v","errorCode":null,"errorMessage":"value %v not encodable with %v","messagePattern":"value (.+?) not encodable with (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/testing/passert/passert.go","lineNumber":120,"sourceCode":"func emitN(val beam.T, n int, emit func(t beam.T)) {\n\tfor i := 0; i < n; i++ {\n\t\temit(val)\n\t}\n}\n\ntype indexEntry struct {\n\tcount int\n\tvalue beam.T\n}\n\nfunc index(enc beam.ElementEncoder, iter func(*beam.T) bool) (map[string]indexEntry, error) {\n\tret := make(map[string]indexEntry)\n\n\tvar val beam.T\n\tfor iter(&val) {\n\t\tvar buf bytes.Buffer\n\t\tif err := enc.Encode(val, &buf); err != nil {\n\t\t\treturn nil, errors.Errorf(\"value %v not encodable with %v\", val, enc)\n\t\t}\n\t\tencoded := buf.String()\n\n\t\tcur := ret[encoded]\n\t\tret[encoded] = indexEntry{count: cur.count + 1, value: val}\n\t}\n\treturn ret, nil\n}\n\n// True asserts that all elements satisfy the given predicate.\nfunc True(s beam.Scope, col beam.PCollection, fn any) beam.PCollection {\n\tfail(s, filter.Exclude(s, col, fn), \"predicate(%v) = false, want true\")\n\treturn col\n}\n\n// False asserts that the given predicate does not satisfy any element in the condition.\nfunc False(s beam.Scope, col beam.PCollection, fn any) beam.PCollection {\n\tfail(s, filter.Include(s, col, fn), \"predicate(%v) = true, want false\")","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/testing/passert/passert.go#L102-L138","documentation":"passert builds an in-memory index of a PCollection by encoding each element with the pipeline's coder, using the encoded bytes as a map key for dedup/counting. If encoding any element fails, index returns 'value %v not encodable with %v'.","triggerScenarios":"A ProcessElement-side call to index encounters a value the provided enc.Encode cannot serialize — a type with no registered coder, a func/chan/interface element, or a failing custom coder.","commonSituations":"Asserting on PCollections containing unsupported types (funcs, channels, structs with non-encodable fields); buggy custom coders; generic interface element types without concrete coders.","solutions":["Ensure the element type has a working registered coder; implement a custom coder if needed.","Remove unsupported field types (func, chan, unsafe pointers) from element structs.","Test the coder directly on a sample value to reproduce the failure.","Convert elements to a simpler encodable type before asserting."],"exampleFix":"// before\ntype weirdDoFn struct{ cb func(int) } // func field not encodable\n// after\ntype weirdDoFn struct{} // drop non-encodable fields or provide a custom coder","handlingStrategy":"validation","validationCode":"var buf bytes.Buffer\nif err := enc.Encode(sampleValue, &buf); err != nil {\n\tt.Fatalf(\"element type not encodable, assertion will fail: %v\", err)\n}","typeGuard":"func encodable(v any, enc Coder) bool {\n\tvar buf bytes.Buffer\n\treturn enc.Encode(v, &buf) == nil\n}","tryCatchPattern":"if err := beamx.Execute(ctx, p); err != nil {\n\tif strings.Contains(err.Error(), \"not encodable with\") {\n\t\t// register/implement a coder for the failing element type\n\t}\n}","preventionTips":["Avoid func/chan fields in DoFn element structs.","Provide custom coders for complex types.","Smoke-test coders on sample values before running assertions."],"tags":["go","beam","testing","passert","coder","serialization"],"backgroundTag":"json-marshal-failed","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"}