{"record":{"id":"b3a96699421773c4","repo":"apache/beam","slug":"unrecognized-state-type-v-for-state-v-currently-the-only","errorCode":null,"errorMessage":"Unrecognized state type %v for state %v. Currently the only supported statetypes are state.Value, state.Combining, state.Bag, state.Set, state.Map, and state.OrderedList","messagePattern":"Unrecognized state type (.+?) for state (.+?)\\. Currently the only supported statetypes are state\\.Value, state\\.Combining, state\\.Bag, state\\.Set, state\\.Map, and state\\.OrderedList","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/graph/fn.go","lineNumber":1372,"sourceCode":"\t\t\t\t\"All stateful DoFns must take a key/value pair as an input.\")\n\t\t}\n\t\tif len(ps) == 0 {\n\t\t\terr := errors.Errorf(\"ProcessElement uses a StateProvider, but noState structs are attached to the DoFn\")\n\t\t\treturn errors.SetTopLevelMsgf(err, \"ProcessElement uses a StateProvider, but no State structs are \"+\n\t\t\t\t\"attached to the DoFn. Ensure that you are including the State structs you're using to read/write\"+\n\t\t\t\t\"global state as public uppercase member variables.\")\n\t\t}\n\t\tstateKeys := make(map[string]state.PipelineState)\n\t\tfor _, s := range ps {\n\t\t\tk := s.StateKey()\n\t\t\tif orig, ok := stateKeys[k]; ok {\n\t\t\t\terr := errors.Errorf(\"Duplicate state key %v\", k)\n\t\t\t\treturn errors.SetTopLevelMsgf(err, \"Duplicate state key %v used by %v and %v. Ensure that state keys are\"+\n\t\t\t\t\t\"unique per DoFn\", k, orig, s)\n\t\t\t}\n\t\t\tt := s.StateType()\n\t\t\tif t != state.TypeValue && t != state.TypeBag && t != state.TypeCombining && t != state.TypeSet && t != state.TypeMap && t != state.TypeOrderedList {\n\t\t\t\terr := errors.Errorf(\"Unrecognized state type %v for state %v\", t, s)\n\t\t\t\treturn errors.SetTopLevelMsgf(err, \"Unrecognized state type %v for state %v. Currently the only supported state\"+\n\t\t\t\t\t\"types are state.Value, state.Combining, state.Bag, state.Set, state.Map, and state.OrderedList\", t, s)\n\t\t\t}\n\t\t\tstateKeys[k] = s\n\t\t}\n\t} else {\n\t\tif len(ps) > 0 {\n\t\t\terr := errors.Errorf(\"ProcessElement doesn't use a StateProvider, but State structs are attached to \"+\n\t\t\t\t\"the DoFn: %v\", ps)\n\t\t\treturn errors.SetTopLevelMsgf(err, \"ProcessElement doesn't use a StateProvider, but State structs are \"+\n\t\t\t\t\"attached to the DoFn: %v\\nEnsure that you are using the StateProvider to perform any reads or writes\"+\n\t\t\t\t\"of pipeline state.\", ps)\n\t\t}\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":1354,"sourceCodeEnd":1390,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/graph/fn.go#L1354-L1390","documentation":"Beam Go restricts pipeline state to a known set of types: state.Value, state.Combining, state.Bag, state.Set, state.Map, and state.OrderedList. When a State struct attached to a DoFn reports a StateType outside this set, validation throws this error because the runner cannot serialize or manage the unknown state kind.","triggerScenarios":"Attaching a custom struct implementing the state interface with an unrecognized StateType(), or using a state type added in a newer Beam version while running an older runtime (or vice versa) so the type constant isn't in the validator's whitelist.","commonSituations":"Implementing a custom PipelineState abstraction; Beam version mismatch between pipeline construction and the fn.go validation code; hand-written state structs copied incorrectly.","solutions":["Replace the custom state with one of the supported types: state.Value, state.Bag, state.Combining, state.Set, state.Map, or state.OrderedList.","Align Beam SDK versions (go.mod) so the state type is recognized by the validator.","Remove the invalid State field if it isn't actually needed."],"exampleFix":"// before\ntype CacheFn struct {\n    LRU state.Custom[...] // unknown state type\n}\n// after\ntype CacheFn struct {\n    Cache state.Map[string, []byte]\n}","handlingStrategy":"validation","validationCode":"// only use supported state generics\nvar _ state.Value[string, int]\nvar _ state.Bag[string]\nvar _ state.Map[string, []byte]\nvar _ state.Set[string]\nvar _ state.OrderedList[int]","typeGuard":"func isSupportedState(s state.PipelineState) bool {\n    switch s.StateType() {\n    case state.TypeValue, state.TypeBag, state.TypeCombining, state.TypeSet, state.TypeMap, state.TypeOrderedList:\n        return true\n    }\n    return false\n}","tryCatchPattern":"if err := beam.Run(ctx, p); err != nil {\n    if strings.Contains(err.Error(), \"Unrecognized state type\") {\n        log.Fatalf(\"swap the custom state for a supported state type: %v\", err)\n    }\n    return err\n}","preventionTips":["Only use the six documented state kinds; never hand-roll custom state types","Keep go.mod Beam SDK version consistent with runner/runtime versions","Read the state API docs before inventing new state abstractions"],"tags":["go","apache-beam","dofn","state","unsupported-type"],"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-14T16:17:12.679Z"}