{"record":{"id":"7c23ac9b977f81b0","repo":"hyperledger/fabric","slug":"could-not-unmarshal-state-for-key-s","errorCode":null,"errorMessage":"could not unmarshal state for key %s","messagePattern":"could not unmarshal state for key (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/lifecycle/serializer.go","lineNumber":410,"sourceCode":"\terr = proto.Unmarshal(metadataBin, metadata)\n\tif err != nil {\n\t\treturn nil, false, errors.Wrapf(err, \"could not unmarshal metadata for namespace %s/%s\", namespace, name)\n\t}\n\n\treturn metadata, true, nil\n}\n\nfunc (s *Serializer) DeserializeField(namespace, name, field string, state ReadableState) (*lb.StateData, error) {\n\tkeyName := FieldKey(namespace, name, field)\n\tvalue, err := state.GetState(keyName)\n\tif err != nil {\n\t\treturn nil, errors.WithMessagef(err, \"could not get state for key %s\", keyName)\n\t}\n\n\tstateData := &lb.StateData{}\n\terr = proto.Unmarshal(value, stateData)\n\tif err != nil {\n\t\treturn nil, errors.Wrapf(err, \"could not unmarshal state for key %s\", keyName)\n\t}\n\n\treturn stateData, nil\n}\n\nfunc (s *Serializer) DeserializeFieldAsString(namespace, name, field string, state ReadableState) (string, error) {\n\tvalue, err := s.DeserializeField(namespace, name, field, state)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tif value.Type == nil {\n\t\treturn \"\", nil\n\t}\n\toneOf, ok := value.Type.(*lb.StateData_String_)\n\tif !ok {\n\t\treturn \"\", errors.Errorf(\"expected key %s/fields/%s/%s to encode a value of type String, but was %T\", namespace, name, field, value.Type)\n\t}\n\treturn oneOf.String_, nil","sourceCodeStart":392,"sourceCodeEnd":428,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/lifecycle/serializer.go#L392-L428","documentation":"Returned by Serializer.DeserializeField when the raw value stored under a fields key cannot be proto-unmarshaled into StateData. Corrupt or version-mismatched state for that field is the cause; the state read itself succeeded.","triggerScenarios":"Thrown at core/chaincode/lifecycle/serializer.go:410 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the wrapped error for the decode failure","Overwrite the corrupted field key by re-approving/committing the chaincode definition"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}