{"record":{"id":"5843e403d3506788","repo":"hyperledger/fabric","slug":"expected-key-s-fields-s-s-to-encode-a-value-of","errorCode":null,"errorMessage":"expected key %s/fields/%s/%s to encode a value of type String, but was %T","messagePattern":"expected key (.+?)/fields/(.+?)/(.+?) to encode a value of type String, but was %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/lifecycle/serializer.go","lineNumber":426,"sourceCode":"\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\n}\n\nfunc (s *Serializer) DeserializeFieldAsBytes(namespace, name, field string, state ReadableState) ([]byte, error) {\n\tvalue, err := s.DeserializeField(namespace, name, field, state)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif value.Type == nil {\n\t\treturn nil, nil\n\t}\n\toneOf, ok := value.Type.(*lb.StateData_Bytes)\n\tif !ok {\n\t\treturn nil, errors.Errorf(\"expected key %s to encode a value of type []byte, but was %T\", FieldKey(namespace, name, field), value.Type)\n\t}\n\treturn oneOf.Bytes, nil\n}","sourceCodeStart":408,"sourceCodeEnd":444,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/lifecycle/serializer.go#L408-L444","documentation":"Returned by Serializer.DeserializeFieldAsString when the stored StateData oneof is set but is not the String variant — e.g. an Int64 or Bytes was stored where the struct field expects a string. A type mismatch between the Go field and the encoded state.","triggerScenarios":"Thrown at core/chaincode/lifecycle/serializer.go:426 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the field was committed as a string value","Re-commit the chaincode definition with the correct field type"],"exampleFix":null,"handlingStrategy":"type-guard","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"}