{"record":{"id":"caec674c9c7c0a2f","repo":"apache/beam","slug":"invalid-coder-caec67","errorCode":null,"errorMessage":"Invalid Coder","messagePattern":"Invalid Coder","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/coder.go","lineNumber":80,"sourceCode":"\n// Coder defines how to encode and decode values of type 'A' into byte streams.\n// Coders are attached to PCollections of the same type. For PCollections\n// consumed by GBK, the attached coders are required to be deterministic.\ntype Coder struct {\n\tcoder *coder.Coder\n}\n\n// IsValid returns true iff the Coder is valid. Any use of an invalid Coder\n// will result in a panic.\nfunc (c Coder) IsValid() bool {\n\treturn c.coder != nil\n}\n\n// Type returns the full type 'A' of elements the coder can encode and decode.\n// 'A' must be a concrete full type, such as int or KV<int,string>.\nfunc (c Coder) Type() FullType {\n\tif !c.IsValid() {\n\t\tpanic(\"Invalid Coder\")\n\t}\n\treturn c.coder.T\n}\n\nfunc (c Coder) String() string {\n\tif c.coder == nil {\n\t\treturn \"$\"\n\t}\n\treturn c.coder.String()\n}\n\n// IsDeterministic reports whether this coder produces a byte-deterministic\n// encoding: encoding two equal values always yields identical byte\n// sequences.\n//\n// Determinism is required for any coder used as a state key in a stateful\n// DoFn or as the key component of a KV consumed by GroupByKey /\n// GroupIntoBatches. A non-deterministic key coder would silently corrupt","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/coder.go#L62-L98","documentation":"Coder.Type() returns the FullType of elements a Beam Go coder can encode/decode, but panics with 'Invalid Coder' if the Coder is the zero value (its internal coder pointer is nil) — i.e. IsValid() is false. The library treats calling Type() on an invalid coder as a programming error.","triggerScenarios":"Declaring a beam.Coder variable without initializing it (var c beam.Coder; c.Type()) or receiving a zero-value Coder from a struct field/map lookup that was never populated, then calling Type().","commonSituations":"Storing Coders in maps or structs with missing initialization; error-swallowing constructors that returned an empty Coder; reflection-driven code paths building coders dynamically.","solutions":["Call c.IsValid() before calling Type() and handle the invalid case explicitly","Ensure the Coder was constructed via beam.NewCoder (checking its returned error upstream)","Trace where the zero-value Coder originated — usually an unchecked error earlier in construction"],"exampleFix":"// before\nfmt.Println(coder.Type())\n// after\nif coder.IsValid() {\n\tfmt.Println(coder.Type())\n} else {\n\treturn errors.New(\"coder was never initialized\")\n}","handlingStrategy":"type-guard","validationCode":"if !c.IsValid() {\n\treturn errors.New(\"coder not initialized\")\n}","typeGuard":"func (c Coder) IsValid() bool { return c.coder != nil }","tryCatchPattern":"func safeType(c beam.Coder) (t typex.FullType, err error) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\terr = fmt.Errorf(\"invalid coder: %v\", r)\n\t\t}\n\t}()\n\treturn c.Type(), nil\n}","preventionTips":["Always construct coders via beam.NewCoder and check errors at that point","Never store zero-value beam.Coder in maps/structs; store *beam.Coder or validate on use"],"tags":["go","apache-beam","panic","coder"],"backgroundTag":"null-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}