{"record":{"id":"3f950822956977d0","repo":"hyperledger/fabric","slug":"error-unmarshalling-chaincodeaction","errorCode":null,"errorMessage":"error unmarshalling ChaincodeAction","messagePattern":"error unmarshalling ChaincodeAction","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"protoutil/unmarshalers.go","lineNumber":123,"sourceCode":"// 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) {\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) {","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/protoutil/unmarshalers.go#L105-L141","documentation":"Returned by protoutil.UnmarshalChaincodeAction when proto.Unmarshal fails to decode bytes into a peer.ChaincodeAction. The wrap adds message-type context to the underlying protobuf error. It means the action bytes (typically ProposalResponsePayload.Extension or the transaction action's results) are invalid or of the wrong type.","triggerScenarios":"Calling UnmarshalChaincodeAction on results fields that are empty, truncated, or actually another message type; reached from transaction validation (extractDependenciesForTx, ValidateLSCCInvocation), read-write set extraction, and CLI invoke/query flows.","commonSituations":"Parsing committed transactions from blocks where the action payload was produced by a different Fabric version; extracting rwset bytes from the wrong field; corrupted transaction records.","solutions":["Verify you pass the correct field (ChaincodeAction lives in ProposalResponsePayload.Extension / Action.Results), not the parent payload bytes.","Check for empty/truncated results before unmarshaling and fail fast with context.","Ensure the transaction was produced by a Fabric version compatible with your parser.","Validate the parent structures first (Envelope -> Payload -> Transaction -> Action) to ensure field offsets are right.","Log length and base64 of failing bytes to diagnose corruption."],"exampleFix":"// before\naction, _ := protoutil.UnmarshalChaincodeAction(prpBytes) // parent payload, wrong bytes\n// after\nprp, _ := protoutil.UnmarshalProposalResponsePayload(prpBytes)\naction, err := protoutil.UnmarshalChaincodeAction(prp.Extension)\nif err != nil {\n    return fmt.Errorf(\"bad chaincode action: %w\", err)\n}","handlingStrategy":"validation","validationCode":"func validChaincodeAction(prp *peer.ProposalResponsePayload) bool {\n    return prp != nil && len(prp.Extension) > 0\n}","typeGuard":"func isChaincodeAction(v any) bool {\n    _, ok := v.(*peer.ChaincodeAction)\n    return ok\n}","tryCatchPattern":"action, err := protoutil.UnmarshalChaincodeAction(prp.Extension)\nif err != nil {\n    return fmt.Errorf(\"cannot extract chaincode action: %w\", err)\n}","preventionTips":["Unmarshal the ProposalResponsePayload first and use its Extension field","Check for empty results before unmarshaling","Validate the full structure chain (Envelope->Payload->Transaction) in order","Keep transaction producer and parser on compatible Fabric versions"],"tags":["fabric","protobuf","unmarshal","chaincode","transaction"],"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"}