{"record":{"id":"5396f94ceb135276","repo":"hyperledger/fabric","slug":"error-unmarshalling-chaicnodeevent","errorCode":null,"errorMessage":"error unmarshalling ChaicnodeEvent","messagePattern":"error unmarshalling ChaicnodeEvent","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"protoutil/unmarshalers.go","lineNumber":137,"sourceCode":"// 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) {\n\tprop := &peer.Proposal{}\n\terr := proto.Unmarshal(propBytes, prop)\n\treturn prop, errors.Wrap(err, \"error unmarshalling Proposal\")\n}\n\n// UnmarshalTransaction unmarshals bytes to a Transaction\nfunc UnmarshalTransaction(txBytes []byte) (*peer.Transaction, error) {","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/protoutil/unmarshalers.go#L119-L155","documentation":"Returned by protoutil.UnmarshalChaincodeEvents when proto.Unmarshal fails to decode bytes into a peer.ChaincodeEvent. Note the wrapped message text contains a typo (\"ChaicnodeEvent\") in this library version. It indicates the event bytes are empty, truncated, or not an encoded ChaincodeEvent.","triggerScenarios":"Calling UnmarshalChaincodeEvents on TxReadWriteSet/chaincode action event fields that are empty (chaincode emitted no event), corrupted, or of another message type; used in filtered block/event processing (toFilteredActions, eventDiff).","commonSituations":"Listening to block events where some transactions legitimately have no chaincode event; parsing events across differing Fabric versions; event payloads corrupted by custom serialization.","solutions":["Check for empty event bytes first — a nil event is normal when the chaincode emits none — before treating failure as an error.","Verify the bytes come from ChaincodeAction.Events, not another field.","Ensure chaincode SetEvent usage marshals plain bytes compatible with the peer's protobuf version.","Upgrade/align peer and consumer SDK versions so the ChaincodeEvent schema matches.","On failure, skip the transaction's event (log and continue) rather than aborting block processing."],"exampleFix":"// before\nev, _ := protoutil.UnmarshalChaincodeEvents(action.Events) // panics later on nil use\n// after\nif len(action.Events) == 0 {\n    return nil // no event emitted\n}\nev, err := protoutil.UnmarshalChaincodeEvents(action.Events)\nif err != nil {\n    return fmt.Errorf(\"bad chaincode event: %w\", err)\n}","handlingStrategy":"validation","validationCode":"func hasChaincodeEvent(action *peer.ChaincodeAction) bool {\n    return action != nil && len(action.Events) > 0\n}","typeGuard":"func isChaincodeEvent(v any) bool {\n    ev, ok := v.(*peer.ChaincodeEvent)\n    return ok && ev.ChaincodeId != \"\"\n}","tryCatchPattern":"if len(action.Events) == 0 {\n    return nil // no event emitted, not an error\n}\nev, err := protoutil.UnmarshalChaincodeEvents(action.Events)\nif err != nil {\n    log.Warnf(\"skipping bad chaincode event: %v\", err)\n    return nil\n}","preventionTips":["Treat empty event bytes as 'no event', not a failure","Set chaincode events via SetEvent with plain byte payloads","Continue block processing on individual event failures (log and skip)","Keep chaincode and peer protobuf versions aligned"],"tags":["fabric","protobuf","unmarshal","events","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"}