hyperledger/fabric · error

error unmarshalling ProposalResponse

Error message

error unmarshalling ProposalResponse

What it means

Returned by protoutil.UnmarshalProposalResponse when proto.Unmarshal cannot decode bytes into a peer.ProposalResponse message. The wrapper identifies the failing message type. It indicates the endorsement bytes are not a valid ProposalResponse encoding.

Source

Thrown at protoutil/unmarshalers.go:116

// 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) {
	chaincodeHdrExt := &peer.ChaincodeHeaderExtension{}
	err := proto.Unmarshal(hdrExtension, chaincodeHdrExt)
	return chaincodeHdrExt, errors.Wrap(err, "error unmarshalling ChaincodeHeaderExtension")
}

// UnmarshalProposalResponse unmarshals bytes to a ProposalResponse
func UnmarshalProposalResponse(prBytes []byte) (*peer.ProposalResponse, error) {
	proposalResponse := &peer.ProposalResponse{}
	err := proto.Unmarshal(prBytes, proposalResponse)
	return proposalResponse, errors.Wrap(err, "error unmarshalling ProposalResponse")
}

// UnmarshalChaincodeAction unmarshals bytes to a ChaincodeAction
func UnmarshalChaincodeAction(caBytes []byte) (*peer.ChaincodeAction, error) {
	chaincodeAction := &peer.ChaincodeAction{}
	err := proto.Unmarshal(caBytes, chaincodeAction)
	return chaincodeAction, errors.Wrap(err, "error unmarshalling ChaincodeAction")
}

// UnmarshalResponse unmarshals bytes to a Response
func UnmarshalResponse(resBytes []byte) (*peer.Response, error) {
	response := &peer.Response{}
	err := proto.Unmarshal(resBytes, response)
	return response, errors.Wrap(err, "error unmarshalling Response")
}

// UnmarshalChaincodeEvents unmarshals bytes to a ChaincodeEvent
func UnmarshalChaincodeEvents(eBytes []byte) (*peer.ChaincodeEvent, error) {

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Ensure the bytes are the marshaled peer.ProposalResponse as returned by the endorser, not a subset field.
  2. Check endorsement transport/serialization (avoid re-encoding as string/JSON) to prevent corruption.
  3. Confirm endorser peer and client SDK use compatible Fabric/protobuf versions.
  4. Log byte length and a checksum before/after transfer to detect truncation.
  5. Reject and re-endorse when unmarshal fails rather than proceeding with a zero-value response.

Example fix

// before
respBytes, _ := json.Marshal(endorserResponse)
pr, _ := protoutil.UnmarshalProposalResponse(respBytes)
// after
prBytes := endorserResponse.Payload // raw marshaled ProposalResponse
pr, err := protoutil.UnmarshalProposalResponse(prBytes)
if err != nil {
    return fmt.Errorf("bad endorsement: %w", err)
}
Defensive patterns

Strategy: try-catch

Validate before calling

func validProposalResponse(b []byte) bool {
    return len(b) > 0
}

Type guard

func isProposalResponse(v any) bool {
    _, ok := v.(*peer.ProposalResponse)
    return ok
}

Try / catch

pr, err := protoutil.UnmarshalProposalResponse(b)
if err != nil {
    return fmt.Errorf("corrupt endorsement (%d bytes): %w", len(b), err)
}

Prevention

When it happens

Trigger: Calling UnmarshalProposalResponse with empty bytes, bytes of an endorse-result in another format, truncated responses from a failed endorsement, or responses produced by an incompatible Fabric version.

Common situations: Collecting endorsements and storing/transmitting them with corruption (JSON-escaping, base64 mismatch); passing a raw endorsement payload instead of the full ProposalResponse; SDK/peer version drift.

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


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/a1b3b16382dc24bf. Report an issue: GitHub.