{"record":{"id":"f37351a4d4183325","repo":"apache/beam","slug":"panic-err-top","errorCode":null,"errorMessage":"panic(err)","messagePattern":"panic\\(err\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"sdks/go/pkg/beam/transforms/top/top.go","lineNumber":154,"sourceCode":"\t\ta.list = append(a.list, element)\n\t}\n\ta.data = nil\n\treturn nil\n}\n\nvar (\n\taccumType = reflect.TypeOf((*accum)(nil)).Elem()\n)\n\nfunc init() {\n\tbeam.RegisterType(accumType)\n\tbeam.RegisterCoder(accumType, accumEnc(), accumDec())\n}\n\nfunc accumEnc() func(accum) ([]byte, error) {\n\tbyteEnc, err := coder.EncoderForSlice(reflect.TypeOf((*[][]byte)(nil)).Elem())\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn func(a accum) ([]byte, error) {\n\t\tif len(a.list) > 0 && a.enc == nil {\n\t\t\treturn nil, errors.Errorf(\"top.accum: element encoder unspecified with non-zero elements: %v data available\", len(a.data))\n\t\t}\n\t\tvar values [][]byte\n\t\tif len(a.list) == 0 && len(a.data) > 0 {\n\t\t\tvalues = a.data\n\t\t}\n\t\tfor _, value := range a.list {\n\t\t\tvar buf bytes.Buffer\n\t\t\tif err := a.enc.Encode(value, &buf); err != nil {\n\t\t\t\treturn nil, errors.WithContextf(err, \"top.accum: marshalling %v\", value)\n\t\t\t}\n\t\t\tvalues = append(values, buf.Bytes())\n\t\t}\n\n\t\tvar buf bytes.Buffer","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/transforms/top/top.go#L136-L172","documentation":"top's package init registers a coder for the accum type; accumEnc builds a slice-of-bytes encoder via coder.EncoderForSlice. If constructing that encoder fails (unsupported element type for the slice coder), the package panics at init time with the returned error. This is an internal invariant failure, not something user data normally triggers.","triggerScenarios":"An unexpected failure in coder.EncoderForSlice for [][]byte while the top package initializes (init calls accumEnc via beam.RegisterCoder). Practically only triggered by a Beam SDK/coder registry bug or version incompatibility.","commonSituations":"Broken or mismatched Beam Go SDK installation; vendored dependency version skew where the coder package changed behavior; custom forks/patches to the coder package.","solutions":["Run 'go build ./...' and update apache/beam sdks to a consistent, released version (go get -u github.com/apache/beam/sdks/v2/go/...).","Check that the beam coder package is unmodified (no vendored patches) and matches the transforms/top package.","Reproduce with a minimal program importing top; if it panics at init on a stock version, file a Beam JIRA with the version."],"exampleFix":"// before\ngo.mod: github.com/apache/beam/sdks/v2 v2.45.0 mixed with v2.54.0 packages\n\n// after\ngo get github.com/apache/beam/sdks/v2/go@v2.54.0 && go mod tidy","handlingStrategy":"fallback","validationCode":"// package-level: verify a program importing top initializes in CI\nfunc TestTopInit(t *testing.T) {\n    _ = top.Largest // forces package init; a panic here fails the test\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        log.Fatalf(\"beam top package failed to init (SDK version skew?): %v\", r)\n    }\n}()","preventionTips":["Pin all apache/beam sdks/v2 packages to a single released version.","Avoid vendored patches to beam's coder package.","Add a smoke test that imports transforms/top so init failures surface in CI."],"tags":["go","apache-beam","panic","init","coder"],"backgroundTag":"module-init-failed","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"}