hyperledger/fabric · error
error unmarshalling Response
Error message
error unmarshalling Response
What it means
Returned by protoutil.UnmarshalResponse when proto.Unmarshal cannot decode bytes into a peer.Response message. The wrapper names the failing message type in the error. It indicates the bytes are not a valid Response (the chaincode invocation's status/message/payload structure).
Source
Thrown at protoutil/unmarshalers.go:130
// 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) {
chaincodeEvent := &peer.ChaincodeEvent{}
err := proto.Unmarshal(eBytes, chaincodeEvent)
return chaincodeEvent, errors.Wrap(err, "error unmarshalling ChaicnodeEvent")
}
// UnmarshalProposalResponsePayload unmarshals bytes to a ProposalResponsePayload
func UnmarshalProposalResponsePayload(prpBytes []byte) (*peer.ProposalResponsePayload, error) {
prp := &peer.ProposalResponsePayload{}
err := proto.Unmarshal(prpBytes, prp)
return prp, errors.Wrap(err, "error unmarshalling ProposalResponsePayload")
}
// UnmarshalProposal unmarshals bytes to a Proposal
func UnmarshalProposal(propBytes []byte) (*peer.Proposal, error) {View on GitHub (pinned to 2736b63f8f)
Solutions
- Ensure the bytes are the Response field of ProposalResponsePayload (prp.Response), not the whole payload or extension.
- Check len(resBytes) > 0 before unmarshaling; return a clear error for absent responses.
- Align protobuf/Fabric versions between producer and consumer of the response.
- Avoid re-encoding responses through text formats (JSON/base64 round trips) that can corrupt them.
- Handle the error by returning the failure to the caller instead of using a zero-value Response.
Example fix
// before
res, _ := protoutil.UnmarshalResponse(prp.Extension)
// after
res, err := protoutil.UnmarshalResponse(prp.Response)
if err != nil {
return fmt.Errorf("bad chaincode response: %w", err)
} Defensive patterns
Strategy: validation
Validate before calling
func validResponse(prp *peer.ProposalResponsePayload) bool {
return prp != nil && len(prp.Response) > 0
} Type guard
func isResponse(v any) bool {
_, ok := v.(*peer.Response)
return ok
} Try / catch
res, err := protoutil.UnmarshalResponse(prp.Response)
if err != nil {
return fmt.Errorf("invalid chaincode response: %w", err)
} Prevention
- Pass prp.Response specifically, not payload or extension bytes
- Treat empty Response bytes as a distinct case with its own error
- Avoid text-format round trips that corrupt binary protobuf
- Verify peer/SDK schema versions match
When it happens
Trigger: Calling UnmarshalResponse on response bytes that are empty, truncated, or actually another message type (e.g. ChaincodeAction bytes); reached from TestProposalResponse and endorsement result processing.
Common situations: Extracting the response from the wrong field of a ProposalResponsePayload; processing responses written/read with mismatched protobuf schemas; corrupted stored endorsements.
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 ChaincodeHeaderExtension
- error unmarshalling ChaincodeAction
- error unmarshalling ChaicnodeEvent
- error unmarshalling
- error unmarshalling original config
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/1f66b37e4e09a0fc.
Report an issue: GitHub.