{"record":{"id":"bb0571406f5dc164","repo":"apache/beam","slug":"nil-coder-at-index-v","errorCode":null,"errorMessage":"nil coder at index: %v","messagePattern":"nil coder at index: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/graph/coder/coder.go","lineNumber":574,"sourceCode":"\n// CoderFrom is a helper that creates a Coder from a CustomCoder.\nfunc CoderFrom(c *CustomCoder) *Coder {\n\treturn &Coder{Kind: Custom, T: typex.New(c.Type), Custom: c}\n}\n\n// Types returns a slice of types used by the supplied coders.\nfunc Types(list []*Coder) []typex.FullType {\n\tvar ret []typex.FullType\n\tfor _, c := range list {\n\t\tret = append(ret, c.T)\n\t}\n\treturn ret\n}\n\nfunc checkCodersNotNil(list []*Coder) {\n\tfor i, c := range list {\n\t\tif c == nil {\n\t\t\tpanic(fmt.Sprintf(\"nil coder at index: %v\", i))\n\t\t}\n\t}\n}\n","sourceCodeStart":556,"sourceCodeEnd":578,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/graph/coder/coder.go#L556-L578","documentation":"checkCodersNotNil is an internal invariant check that panics when a composite coder (KV, N, or CoGBK) is constructed with a nil element coder. The Apache Beam Go SDK requires every component coder of a composite type to be a fully-formed *Coder so the pipeline can serialize all elements. A nil in the list means the caller passed an unconstructed or unset coder.","triggerScenarios":"Calling coder.NewKV(nil, v), coder.NewN(nil), coder.NewCoGBK(nil, ...) or any composite constructor with a nil entry anywhere in the coder slice; the panic fires during pipeline graph construction with the offending slice index.","commonSituations":"Building custom transforms where a component coder comes from a map/registry lookup that missed; conditional logic that leaves a coder variable nil on some paths; refactoring that reordered coder construction so one is used before assignment.","solutions":["Find the coder at the index printed in the panic and fix why it is nil (failed lookup, wrong variable, skipped initialization)","Ensure every component coder is constructed via coder.New* before building the composite coder","If the type is unsupported, use coder.NewUnknown instead of passing nil","Add a non-nil check/log before composing coders in custom pipeline code"],"exampleFix":"// before\nc := coder.NewKV(kvCoder[0], kvCoder[1]) // kvCoder[1] may be nil\n// after\nif kvCoder[0] == nil || kvCoder[1] == nil {\n\tlog.Fatalf(\"component coder missing\")\n}\nc := coder.NewKV(kvCoder[0], kvCoder[1])","handlingStrategy":"validation","validationCode":"for i, c := range coders {\n\tif c == nil {\n\t\treturn fmt.Errorf(\"coder at index %d is nil\", i)\n\t}\n}","typeGuard":"func hasNilCoder(list []*coder.Coder) bool {\n\tfor _, c := range list {\n\t\tif c == nil {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}","tryCatchPattern":"// Go panics are not recoverable at the call site unless wrapped:\nfunc safeNewKV(list []*coder.Coder) (c *coder.Coder, err error) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\terr = fmt.Errorf(\"checkCodersNotNil: %v\", r)\n\t\t}\n\t}()\n\treturn coder.NewKV(list[0], list[1]), nil\n}","preventionTips":["Initialize all component coders before composing composite coders","Use coder.NewUnknown rather than nil for unknown types","Check registry/map lookups for coder types before use"],"tags":["go","beam","coder","nil-pointer"],"backgroundTag":"null-argument","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"}