{"record":{"id":"4b21e19b78820707","repo":"apache/beam","slug":"failed-to-decode-union-value-v-for-key-v","errorCode":null,"errorMessage":"failed to decode union value '%v' for key %v","messagePattern":"failed to decode union value '(.+?)' for key (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/exec/cogbk.go","lineNumber":172,"sourceCode":"func (f *filterStream) Read() (*FullValue, error) {\n\tfor {\n\t\telm, err := f.real.Read()\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tkey := elm.Elm.(int)\n\t\tvalue := elm.Elm2.([]byte)\n\n\t\t// Transform KV<int,[]byte> into V iff key == N\n\n\t\tif key != f.n {\n\t\t\tcontinue // skip other keys\n\t\t}\n\n\t\tv, err := f.dec.Decode(bytes.NewReader(value))\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrapf(err, \"failed to decode union value '%v' for key %v\", value, key)\n\t\t}\n\t\tv.Timestamp = elm.Timestamp\n\t\tv.Windows = elm.Windows\n\t\treturn v, nil\n\t}\n}\n","sourceCodeStart":154,"sourceCodeEnd":179,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/exec/cogbk.go#L154-L179","documentation":"During CoGBK union value decoding, the reader encounters a key matching this union's index but the encoded value bytes cannot be decoded by the union's decoder. The error wraps the underlying decode failure with the offending bytes and key for diagnosis.","triggerScenarios":"Read() on a CoGBK/union stream where f.dec.Decode fails on the value bytes — typically when the wire bytes were written with a different coder version or schema than the one being used to read.","commonSituations":"Schema evolution across pipeline versions (old data read by new coder), cross-language pipelines whose union coders disagree, corrupted or truncated blob in the CoGBK shard.","solutions":["Inspect the wrapped inner error to find the actual decode failure.","Ensure producer and consumer use the same coder/schema version for the union value.","Re-run or regenerate the data if it was written by an incompatible pipeline version."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"v, err := ds.Read(ctx)\nif err != nil {\n\tvar decErr interface{ Unwrap() error }\n\tif errors.As(err, &wrapped) && strings.Contains(err.Error(), \"failed to decode union value\") {\n\t\t// log key/bytes and fail fast; data is schema-incompatible\n\t}\n\treturn err\n}","preventionTips":["Keep coder/schema versions in sync between writers and readers.","Avoid changing union value coders without migrating existing data.","Log the inner decode error (errors.Unwrap) to identify the coder mismatch."],"tags":["go","beam","decoding","cogbk"],"backgroundTag":"schema-validation-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}