{"record":{"id":"1f66b37e4e09a0fc","repo":"hyperledger/fabric","slug":"error-unmarshalling-response","errorCode":null,"errorMessage":"error unmarshalling Response","messagePattern":"error unmarshalling Response","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"protoutil/unmarshalers.go","lineNumber":130,"sourceCode":"// UnmarshalProposalResponse unmarshals bytes to a ProposalResponse\nfunc UnmarshalProposalResponse(prBytes []byte) (*peer.ProposalResponse, error) {\n\tproposalResponse := &peer.ProposalResponse{}\n\terr := proto.Unmarshal(prBytes, proposalResponse)\n\treturn proposalResponse, errors.Wrap(err, \"error unmarshalling ProposalResponse\")\n}\n\n// UnmarshalChaincodeAction unmarshals bytes to a ChaincodeAction\nfunc UnmarshalChaincodeAction(caBytes []byte) (*peer.ChaincodeAction, error) {\n\tchaincodeAction := &peer.ChaincodeAction{}\n\terr := proto.Unmarshal(caBytes, chaincodeAction)\n\treturn chaincodeAction, errors.Wrap(err, \"error unmarshalling ChaincodeAction\")\n}\n\n// UnmarshalResponse unmarshals bytes to a Response\nfunc UnmarshalResponse(resBytes []byte) (*peer.Response, error) {\n\tresponse := &peer.Response{}\n\terr := proto.Unmarshal(resBytes, response)\n\treturn response, errors.Wrap(err, \"error unmarshalling Response\")\n}\n\n// UnmarshalChaincodeEvents unmarshals bytes to a ChaincodeEvent\nfunc UnmarshalChaincodeEvents(eBytes []byte) (*peer.ChaincodeEvent, error) {\n\tchaincodeEvent := &peer.ChaincodeEvent{}\n\terr := proto.Unmarshal(eBytes, chaincodeEvent)\n\treturn chaincodeEvent, errors.Wrap(err, \"error unmarshalling ChaicnodeEvent\")\n}\n\n// UnmarshalProposalResponsePayload unmarshals bytes to a ProposalResponsePayload\nfunc UnmarshalProposalResponsePayload(prpBytes []byte) (*peer.ProposalResponsePayload, error) {\n\tprp := &peer.ProposalResponsePayload{}\n\terr := proto.Unmarshal(prpBytes, prp)\n\treturn prp, errors.Wrap(err, \"error unmarshalling ProposalResponsePayload\")\n}\n\n// UnmarshalProposal unmarshals bytes to a Proposal\nfunc UnmarshalProposal(propBytes []byte) (*peer.Proposal, error) {","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/protoutil/unmarshalers.go#L112-L148","documentation":"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).","triggerScenarios":"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.","commonSituations":"Extracting the response from the wrong field of a ProposalResponsePayload; processing responses written/read with mismatched protobuf schemas; corrupted stored endorsements.","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."],"exampleFix":"// before\nres, _ := protoutil.UnmarshalResponse(prp.Extension)\n// after\nres, err := protoutil.UnmarshalResponse(prp.Response)\nif err != nil {\n    return fmt.Errorf(\"bad chaincode response: %w\", err)\n}","handlingStrategy":"validation","validationCode":"func validResponse(prp *peer.ProposalResponsePayload) bool {\n    return prp != nil && len(prp.Response) > 0\n}","typeGuard":"func isResponse(v any) bool {\n    _, ok := v.(*peer.Response)\n    return ok\n}","tryCatchPattern":"res, err := protoutil.UnmarshalResponse(prp.Response)\nif err != nil {\n    return fmt.Errorf(\"invalid chaincode response: %w\", err)\n}","preventionTips":["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"],"tags":["fabric","protobuf","unmarshal","response","chaincode"],"backgroundTag":"protobuf-unmarshal-failed","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"}