hyperledger/fabric · error
could not unmarshal key %s to %T
Error message
could not unmarshal key %s to %T
What it means
Returned by Serializer.DeserializeFieldAsProto when proto.Unmarshal fails on the bytes fetched for a proto-typed field. The state bytes were retrieved and were []byte-typed, but do not decode into the target message — corrupt or wrong-version data.
Source
Thrown at core/chaincode/lifecycle/serializer.go:453
}
if value.Type == nil {
return nil, nil
}
oneOf, ok := value.Type.(*lb.StateData_Bytes)
if !ok {
return nil, errors.Errorf("expected key %s to encode a value of type []byte, but was %T", FieldKey(namespace, name, field), value.Type)
}
return oneOf.Bytes, nil
}
func (s *Serializer) DeserializeFieldAsProto(namespace, name, field string, state ReadableState, msg proto.Message) error {
bin, err := s.DeserializeFieldAsBytes(namespace, name, field, state)
if err != nil {
return err
}
err = proto.Unmarshal(bin, msg)
if err != nil {
return errors.Wrapf(err, "could not unmarshal key %s to %T", FieldKey(namespace, name, field), msg)
}
return nil
}
func (s *Serializer) DeserializeFieldAsInt64(namespace, name, field string, state ReadableState) (int64, error) {
value, err := s.DeserializeField(namespace, name, field, state)
if err != nil {
return 0, err
}
if value.Type == nil {
return 0, nil
}
oneOf, ok := value.Type.(*lb.StateData_Int64)
if !ok {
return 0, errors.Errorf("expected key %s to encode a value of type Int64, but was %T", FieldKey(namespace, name, field), value.Type)
}
return oneOf.Int64, nil
}View on GitHub (pinned to 2736b63f8f)
Solutions
- Verify the expected proto type matches what was serialized at that key
- Re-commit the definition so the field is written with the correct proto payload
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at core/chaincode/lifecycle/serializer.go:453 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/602703b3bf8549fe.
Report an issue: GitHub.