hyperledger/fabric · error
error unmarshalling SerializedIdentity
Error message
error unmarshalling SerializedIdentity
What it means
This error is returned by protoutil.UnmarshalSerializedIdentity when proto.Unmarshal fails to decode the input bytes into an msp.SerializedIdentity message. The library wraps the underlying protobuf error with context so callers know which message type failed. It indicates the bytes are not a valid, complete, or correctly-versioned SerializedIdentity protobuf.
Source
Thrown at protoutil/unmarshalers.go:88
// UnmarshalSignatureHeader unmarshals bytes to a SignatureHeader
func UnmarshalSignatureHeader(bytes []byte) (*common.SignatureHeader, error) {
sh := &common.SignatureHeader{}
err := proto.Unmarshal(bytes, sh)
return sh, errors.Wrap(err, "error unmarshalling SignatureHeader")
}
// UnmarshalIdentifierHeader unmarshals bytes to an IdentifierHeader
func UnmarshalIdentifierHeader(bytes []byte) (*common.IdentifierHeader, error) {
ih := &common.IdentifierHeader{}
err := proto.Unmarshal(bytes, ih)
return ih, errors.Wrap(err, "error unmarshalling IdentifierHeader")
}
func UnmarshalSerializedIdentity(bytes []byte) (*msp.SerializedIdentity, error) {
sid := &msp.SerializedIdentity{}
err := proto.Unmarshal(bytes, sid)
return sid, errors.Wrap(err, "error unmarshalling SerializedIdentity")
}
// UnmarshalHeader unmarshals bytes to a Header
func UnmarshalHeader(bytes []byte) (*common.Header, error) {
hdr := &common.Header{}
err := proto.Unmarshal(bytes, hdr)
return hdr, errors.Wrap(err, "error unmarshalling Header")
}
// UnmarshalConfigEnvelope unmarshals bytes to a ConfigEnvelope
func UnmarshalConfigEnvelope(bytes []byte) (*common.ConfigEnvelope, error) {
cfg := &common.ConfigEnvelope{}
err := proto.Unmarshal(bytes, cfg)
return cfg, errors.Wrap(err, "error unmarshalling ConfigEnvelope")
}
// UnmarshalChaincodeHeaderExtension unmarshals bytes to a ChaincodeHeaderExtension
func UnmarshalChaincodeHeaderExtension(hdrExtension []byte) (*peer.ChaincodeHeaderExtension, error) {View on GitHub (pinned to 2736b63f8f)
Solutions
- Verify the input bytes come from a serialized msp.SerializedIdentity (e.g. via id.Serialize() or an envelope's creator field), not a PEM or certificate blob.
- Log len(bytes) and a hex/base64 dump of the input to confirm it is non-empty and consistent.
- Regenerate the identity with a matching Fabric version (peer/MSP and SDK must agree on protobuf definitions).
- Check for truncation/corruption during transport (base64 decode errors, string escaping, file offsets).
- Handle the error path gracefully: reject the input and return a descriptive error instead of panicking on the nil-ish result.
Example fix
// before
sid, err := proto.Marshal(&common.Header{})
identity, _ := protoutil.UnmarshalSerializedIdentity(sid)
// after
creator := envelope.SignatureHeader.Creator // actual SerializedIdentity bytes
identity, err := protoutil.UnmarshalSerializedIdentity(creator)
if err != nil {
return fmt.Errorf("bad creator identity: %w", err)
} Defensive patterns
Strategy: validation
Validate before calling
func validSerializedIdentity(b []byte) bool {
return len(b) > 0 && b[0] == 0x0a // SerializedIdentity: field 1 (Mspid), length-delimited
} Type guard
func isSerializedIdentity(v any) bool {
_, ok := v.(*msp.SerializedIdentity)
return ok
} Try / catch
sid, err := protoutil.UnmarshalSerializedIdentity(b)
if err != nil {
return fmt.Errorf("invalid serialized identity (%d bytes): %w", len(b), err)
} Prevention
- Only feed bytes produced by id.Serialize() or the envelope's creator field into this API
- Check for empty input before calling
- Keep Fabric peer/MSP and SDK versions aligned
- Avoid serializing identities through text formats (JSON/PEM) that alter the bytes
When it happens
Trigger: Calling UnmarshalSerializedIdentity with empty bytes, truncated input, bytes of a different protobuf type (e.g. a Header or Proposal), corrupted certificates/identities read from a block or MSP directory, or input produced by a different Fabric/protobuf version with incompatible encoding.
Common situations: Parsing identity bytes extracted manually from an envelope or block; passing a PEM blob instead of the serialized identity; reading corrupted channel configuration; cross-version fabric-sdk/fabric-peer incompatibility; misconfigured MSP material.
Understand the failure class
Background: "cannot parse invalid wire-format data", "cannot unmarshal", "failed unmarshalling": protobuf unmarshal errors explained — this error's family across 10 libraries.
Related errors
- error unmarshalling
- error unmarshalling original config
- error unmarshalling updated config
- failed unmarshaling identity %s
- failed to unmarshal ApplicationPolicy bytes
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/b2c5fbf484db3d45.
Report an issue: GitHub.