{"record":{"id":"55cb913241d09c44","repo":"apache/beam","slug":"unexpected-opcode-v","errorCode":null,"errorMessage":"unexpected opcode: %v","messagePattern":"unexpected opcode: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/graphx/translate.go","lineNumber":715,"sourceCode":"\t\t\t\tinputs[tag] = nodeID(in)\n\t\t\t}\n\t\t}\n\n\t\tif len(pyld.OutputsMap) != 0 {\n\t\t\tif got, want := len(pyld.OutputsMap), len(edge.Edge.Output); got != want {\n\t\t\t\treturn handleErr(errors.Errorf(\"mismatch'd counts between External tags (%v) and outputs (%v)\", got, want))\n\t\t\t}\n\t\t\toutputs = make(map[string]string)\n\t\t\tfor tag, out := range OutboundTagToNode(pyld.OutputsMap, edge.Edge.Output) {\n\t\t\t\tif _, err := m.addNode(out); err != nil {\n\t\t\t\t\treturn handleErr(err)\n\t\t\t\t}\n\t\t\t\toutputs[tag] = nodeID(out)\n\t\t\t}\n\t\t}\n\n\tdefault:\n\t\terr := errors.Errorf(\"unexpected opcode: %v\", edge.Edge.Op)\n\t\treturn handleErr(err)\n\t}\n\n\tvar transformEnvID = \"\"\n\tif !(spec.Urn == URNGBK || spec.Urn == URNImpulse) {\n\t\ttransformEnvID = m.addDefaultEnv()\n\t}\n\n\ttransform := &pipepb.PTransform{\n\t\tUniqueName:    edge.Name,\n\t\tSpec:          spec,\n\t\tInputs:        inputs,\n\t\tOutputs:       outputs,\n\t\tEnvironmentId: transformEnvID,\n\t\tAnnotations:   annotations,\n\t}\n\tm.transforms[id] = transform\n\tallPIds = append(allPIds, id)","sourceCodeStart":697,"sourceCodeEnd":733,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/graphx/translate.go#L697-L733","documentation":"During pipeline graph marshalling (graphx/translate.go), addMultiEdge converts each in-memory MultiEdge's Operation opcode into a Beam runner-API transform payload. The 'default' branch of the opcode switch is reached when the opcode is not one of the recognized ones (ParDo, GBK, CoGBK, Reshuffle, External, etc.), so the marshaller fails fast with 'unexpected opcode'. This indicates an operation kind the translator does not know how to serialize.","triggerScenarios":"A MultiEdge whose edge.Op is a new/unhandled graph.Op value reaches Marshal — e.g. a custom or newly added Operation type in the beam graph package that translate.go's switch has not been extended for, or a manually constructed graph passed to graphx.Marshal.","commonSituations":"Developers hacking on Beam internals adding a new operation kind without updating the marshaller; running a fork of the Go SDK where an op was introduced but translation support wasn't; building synthetic pipelines programmatically with an invalid op.","solutions":["Update translate.go's opcode switch in addMultiEdge to handle the new graph.Op value and emit the appropriate pipepb transform payload","Verify the pipeline is built with public beam APIs; manually constructed graphs may carry invalid opcodes","Check Go SDK version: code written against a newer graph.Op enum running with an older translate.go needs upgrading","File/report upstream to apache/beam if the op is a standard one that should be supported"],"exampleFix":"// before (translate.go addMultiEdge switch)\ndefault:\n    err := errors.Errorf(\"unexpected opcode: %v\", edge.Edge.Op)\n    return handleErr(err)\n// after\ncase graph.MyNewOp:\n    return m.expandMyNewOp(edge)\ndefault:\n    err := errors.Errorf(\"unexpected opcode: %v\", edge.Edge.Op)\n    return handleErr(err)","handlingStrategy":"validation","validationCode":"// pre-flight: only known ops can be marshalled\nknown := map[graph.Op]bool{graph.ParDo: true, graph.CoGBK: true, graph.Reshuffle: true, graph.External: true}\nif !known[edge.Edge.Op] {\n    return fmt.Errorf(\"op %v not supported by graphx marshaller\", edge.Edge.Op)\n}","typeGuard":"func isKnownOp(op graph.Op) bool {\n    switch op {\n    case graph.ParDo, graph.CoGBK, graph.Reshuffle, graph.External:\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Build pipelines only with public beam APIs, never hand-rolled graphs","When adding new graph.Op values, update translate.go in the same change","Keep the Go SDK at the version matching your pipeline construction code"],"tags":["go","apache-beam","pipeline-marshalling","graph-serialization"],"backgroundTag":"invalid-enum-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"}