{"record":{"id":"43f3b2edb47e0fd4","repo":"apache/beam","slug":"bad-n-v","errorCode":null,"errorMessage":"bad N: %v","messagePattern":"bad N: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/graphx/dataflow.go","lineNumber":125,"sourceCode":"\n\tcase coder.KV:\n\t\tif len(c.Components) != 2 {\n\t\t\treturn nil, errors.Errorf(\"bad KV: %v\", c)\n\t\t}\n\n\t\tkey, err := EncodeCoderRef(c.Components[0])\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tvalue, err := EncodeCoderRef(c.Components[1])\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn &CoderRef{Type: pairType, Components: []*CoderRef{key, value}, IsPairLike: true}, nil\n\n\tcase coder.Nullable:\n\t\tif len(c.Components) != 1 {\n\t\t\treturn nil, errors.Errorf(\"bad N: %v\", c)\n\t\t}\n\t\tinnerref, err := EncodeCoderRef(c.Components[0])\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn &CoderRef{Type: nullableType, Components: []*CoderRef{innerref}}, nil\n\n\tcase coder.Iterable:\n\t\tif len(c.Components) != 1 {\n\t\t\treturn nil, errors.Errorf(\"bad I: %v\", c)\n\t\t}\n\t\tinnerref, err := EncodeCoderRef(c.Components[0])\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn &CoderRef{Type: streamType, Components: []*CoderRef{innerref}}, nil\n\n\tcase coder.CoGBK:","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/graphx/dataflow.go#L107-L143","documentation":"EncodeCoderRef serializes a beam coder into its Dataflow-runner representation. A coder.Nullable must have exactly one component (the inner value coder); if it doesn't, the coder is structurally invalid and the library refuses to encode it rather than emit a corrupt CoderRef to the service. The message includes the offending coder for diagnosis.","triggerScenarios":"Calling EncodeCoderRef (directly or via EncodeCoder/EncodeCoderRefs during pipeline serialization for the Dataflow runner) with a coder.Coder of Kind coder.Nullable whose Components slice has length != 1 (e.g. zero components from a hand-constructed coder, or multiple components from a malformed decode).","commonSituations":"Hand-building Coder structs instead of using coder.New; a schema/typed pipeline where a nullable field's component failed to attach; decoding a CoderRef from a different Beam version whose component count differs, then re-encoding; custom coder wrappers that mislabel themselves as Nullable.","solutions":["Verify the Nullable coder has exactly one component: len(c.Components) == 1 before serialization.","Build nullable coders with the SDK helpers (e.g. derive them from typex.NullableType typed values) instead of constructing coder.Coder literals manually.","Check the pipeline for custom coders overriding a nullable field and fix the override.","If this arose from re-encoding a decoded CoderRef, confirm encode and decode paths are from the same Beam SDK version."],"exampleFix":"// before\nc := &coder.Coder{Kind: coder.Nullable, T: t, Components: nil}\nref, err := graphx.EncodeCoderRef(c)\n\n// after\ninner := graphx.InferCoder(typex.New(typex.StringType))\nc := &coder.Coder{Kind: coder.Nullable, T: typex.New(typex.NullableType, inner.T), Components: []*coder.Coder{inner}}\nref, err := graphx.EncodeCoderRef(c)","handlingStrategy":"validation","validationCode":"func validNullable(c *coder.Coder) bool {\n\treturn c != nil && c.Kind == coder.Nullable && len(c.Components) == 1\n}","typeGuard":"func isCoderOfKind(c *coder.Coder, k coder.Kind) bool { return c != nil && c.Kind == k }","tryCatchPattern":"ref, err := graphx.EncodeCoderRef(c)\nif err != nil {\n\tif strings.Contains(err.Error(), \"bad N\") {\n\t\treturn fmt.Errorf(\"nullable coder must have exactly 1 component: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Always construct nullable coders via SDK constructors, not struct literals","Assert len(c.Components) == 1 in unit tests for custom coder providers","Keep encode/decode SDK versions identical in your tooling"],"tags":["go","beam","coder-serialization","dataflow"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}