{"record":{"id":"9f99be3dc62d6f32","repo":"hyperledger/fabric","slug":"expected-key-s-to-encode-a-value-of-type-byte","errorCode":null,"errorMessage":"expected key %s to encode a value of type []byte, but was %T","messagePattern":"expected key (.+?) to encode a value of type \\[\\]byte, but was %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/lifecycle/serializer.go","lineNumber":441,"sourceCode":"\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}\n\nfunc (s *Serializer) DeserializeFieldAsProto(namespace, name, field string, state ReadableState, msg proto.Message) error {\n\tbin, err := s.DeserializeFieldAsBytes(namespace, name, field, state)\n\tif err != nil {\n\t\treturn err\n\t}\n\terr = proto.Unmarshal(bin, msg)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"could not unmarshal key %s to %T\", FieldKey(namespace, name, field), msg)\n\t}\n\treturn nil\n}\n\nfunc (s *Serializer) DeserializeFieldAsInt64(namespace, name, field string, state ReadableState) (int64, error) {\n\tvalue, err := s.DeserializeField(namespace, name, field, state)","sourceCodeStart":423,"sourceCodeEnd":459,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/lifecycle/serializer.go#L423-L459","documentation":"Returned by Serializer.DeserializeFieldAsBytes when the stored StateData oneof is not the Bytes variant — the key encodes a String or Int64 where []byte was expected, so the value cannot be returned as bytes.","triggerScenarios":"Thrown at core/chaincode/lifecycle/serializer.go:441 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the field was committed as a bytes value (e.g. approval or validation data)","Re-commit the definition with the correctly typed field"],"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"}