{"record":{"id":"a1b3b16382dc24bf","repo":"hyperledger/fabric","slug":"error-unmarshalling-proposalresponse","errorCode":null,"errorMessage":"error unmarshalling ProposalResponse","messagePattern":"error unmarshalling ProposalResponse","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"protoutil/unmarshalers.go","lineNumber":116,"sourceCode":"// UnmarshalConfigEnvelope unmarshals bytes to a ConfigEnvelope\nfunc UnmarshalConfigEnvelope(bytes []byte) (*common.ConfigEnvelope, error) {\n\tcfg := &common.ConfigEnvelope{}\n\terr := proto.Unmarshal(bytes, cfg)\n\treturn cfg, errors.Wrap(err, \"error unmarshalling ConfigEnvelope\")\n}\n\n// UnmarshalChaincodeHeaderExtension unmarshals bytes to a ChaincodeHeaderExtension\nfunc UnmarshalChaincodeHeaderExtension(hdrExtension []byte) (*peer.ChaincodeHeaderExtension, error) {\n\tchaincodeHdrExt := &peer.ChaincodeHeaderExtension{}\n\terr := proto.Unmarshal(hdrExtension, chaincodeHdrExt)\n\treturn chaincodeHdrExt, errors.Wrap(err, \"error unmarshalling ChaincodeHeaderExtension\")\n}\n\n// 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) {","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/protoutil/unmarshalers.go#L98-L134","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the bytes are the marshaled peer.ProposalResponse as returned by the endorser, not a subset field.","Check endorsement transport/serialization (avoid re-encoding as string/JSON) to prevent corruption.","Confirm endorser peer and client SDK use compatible Fabric/protobuf versions.","Log byte length and a checksum before/after transfer to detect truncation.","Reject and re-endorse when unmarshal fails rather than proceeding with a zero-value response."],"exampleFix":"// before\nrespBytes, _ := json.Marshal(endorserResponse)\npr, _ := protoutil.UnmarshalProposalResponse(respBytes)\n// after\nprBytes := endorserResponse.Payload // raw marshaled ProposalResponse\npr, err := protoutil.UnmarshalProposalResponse(prBytes)\nif err != nil {\n    return fmt.Errorf(\"bad endorsement: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"func validProposalResponse(b []byte) bool {\n    return len(b) > 0\n}","typeGuard":"func isProposalResponse(v any) bool {\n    _, ok := v.(*peer.ProposalResponse)\n    return ok\n}","tryCatchPattern":"pr, err := protoutil.UnmarshalProposalResponse(b)\nif err != nil {\n    return fmt.Errorf(\"corrupt endorsement (%d bytes): %w\", len(b), err)\n}","preventionTips":["Store/transport endorsement bytes as opaque binary (no JSON/base64 re-encoding)","Verify byte counts or checksums across transport","Collect endorsements only from peers on the same Fabric version","Re-request endorsement when unmarshal fails instead of using partial data"],"tags":["fabric","protobuf","unmarshal","endorsement"],"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"}