{"record":{"id":"bdd23addd60ba81f","repo":"hyperledger/fabric","slug":"invalid-chaincode-event","errorCode":null,"errorMessage":"invalid chaincode event","messagePattern":"invalid chaincode event","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/committer/txvalidator/v14/vscc_validator.go","lineNumber":124,"sourceCode":"\t\terr = errors.Errorf(\"inconsistent ccid info (%s/%s)\", ccID, respPayload.ChaincodeId.Name)\n\t\tlogger.Errorf(\"%+v\", err)\n\t\treturn peer.TxValidationCode_INVALID_OTHER_REASON, err\n\t}\n\t// sanity check on ccver\n\tif ccVer == \"\" {\n\t\terr = errors.New(\"invalid chaincode version\")\n\t\tlogger.Errorf(\"%+v\", err)\n\t\treturn peer.TxValidationCode_INVALID_OTHER_REASON, err\n\t}\n\n\tvar wrNamespace []string\n\talwaysEnforceOriginalNamespace := v.cr.Capabilities().V1_2Validation()\n\tif alwaysEnforceOriginalNamespace {\n\t\twrNamespace = append(wrNamespace, ccID)\n\t\tif respPayload.Events != nil {\n\t\t\tccEvent := &peer.ChaincodeEvent{}\n\t\t\tif err = proto.Unmarshal(respPayload.Events, ccEvent); err != nil {\n\t\t\t\treturn peer.TxValidationCode_INVALID_OTHER_REASON, errors.Wrapf(err, \"invalid chaincode event\")\n\t\t\t}\n\t\t\tif ccEvent.ChaincodeId != ccID {\n\t\t\t\treturn peer.TxValidationCode_INVALID_OTHER_REASON, errors.Errorf(\"chaincode event chaincode id does not match chaincode action chaincode id\")\n\t\t\t}\n\t\t}\n\t}\n\n\tnamespaces := make(map[string]struct{})\n\tfor _, ns := range txRWSet.NsRwSets {\n\t\t// check to make sure there is no duplicate namespace in txRWSet\n\t\tif _, ok := namespaces[ns.NameSpace]; ok {\n\t\t\treturn peer.TxValidationCode_ILLEGAL_WRITESET, errors.Errorf(\"duplicate namespace '%s' in txRWSet\", ns.NameSpace)\n\t\t}\n\t\tnamespaces[ns.NameSpace] = struct{}{}\n\n\t\tif !v.txWritesToNamespace(ns) {\n\t\t\tcontinue\n\t\t}","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/committer/txvalidator/v14/vscc_validator.go#L106-L142","documentation":"When V1_2Validation capabilities are enabled and the chaincode action includes Events, VSCC unmarshals them as a peer.ChaincodeEvent; the unmarshal failed, so the events bytes are not a valid ChaincodeEvent protobuf. The transaction is invalidated with TxValidationCode_INVALID_OTHER_REASON and the underlying error wrapped in this message.","triggerScenarios":"respPayload.Events contains bytes that do not decode as ChaincodeEvent — e.g. a chaincode emits events serialized with a custom format (JSON, plain string) instead of protobuf, or corrupts the field.","commonSituations":"Chaincode developers using SetEvent with non-protobuf expectations or custom binary payloads inside event bytes; chaincodes ported from other frameworks; shim/proto version mismatches.","solutions":["Fix the chaincode to emit events via the shim's SetEvent with a valid ChaincodeEvent-compatible payload (payload bytes may be arbitrary, but the event wrapper must be standard shim-generated protobuf).","Check the chaincode shim version matches the peer's proto definitions.","Inspect respPayload.Events bytes with protoc --decode_raw to identify the malformed content."],"exampleFix":"// before: custom serialization inside shim event field\nstub.SetEvent(\"evt\", myCustomProtoBytes)\n// after: standard shim event; put custom data in the Event.Payload\nstub.SetEvent(\"evt\", []byte(`{\"k\":\"v\"}`))","handlingStrategy":"validation","validationCode":"if len(respPayload.Events) > 0 {\n    evt := &peer.ChaincodeEvent{}\n    if err := proto.Unmarshal(respPayload.Events, evt); err != nil {\n        return fmt.Errorf(\"events bytes are not a valid ChaincodeEvent: %w\", err)\n    }\n}","typeGuard":"func isValidChaincodeEvent(b []byte) bool {\n\tevt := &peer.ChaincodeEvent{}\n\treturn len(b) == 0 || proto.Unmarshal(b, evt) == nil\n}","tryCatchPattern":"if err := proto.Unmarshal(respPayload.Events, ccEvent); err != nil {\n    return peer.TxValidationCode_INVALID_OTHER_REASON, errors.Wrapf(err, \"invalid chaincode event\")\n}","preventionTips":["Emit events only through stub.SetEvent; never serialize custom message formats into the event field.","Keep chaincode shim and peer proto versions aligned.","Decode respPayload.Events with protoc --decode_raw when debugging event format issues."],"tags":["fabric","transaction-validation","chaincode-events"],"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"}