{"record":{"id":"8e1a04ffbbc14e82","repo":"hyperledger/fabric","slug":"marshal-failed","errorCode":null,"errorMessage":"marshal failed","messagePattern":"marshal failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/handler.go","lineNumber":746,"sourceCode":"\t\t\treturn nil, errors.New(\"private data APIs are not allowed in chaincode Init()\")\n\t\t}\n\t\tif err = errorIfCreatorHasNoReadPermission(namespaceID, collection, txContext); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tres, err = txContext.TXSimulator.GetPrivateDataMultipleKeys(namespaceID, collection, getState.GetKeys())\n\t} else {\n\t\tres, err = txContext.TXSimulator.GetStateMultipleKeys(namespaceID, getState.GetKeys())\n\t}\n\tif err != nil {\n\t\treturn nil, errors.WithStack(err)\n\t}\n\tif len(res) == 0 {\n\t\tchaincodeLogger.Debugf(\"[%s] No state associated with keys: %v. Sending %s with an empty payload\", shorttxid(msg.Txid), getState.GetKeys(), pb.ChaincodeMessage_RESPONSE)\n\t}\n\n\tpayloadBytes, err := proto.Marshal(&pb.GetStateMultipleResult{Values: res})\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"marshal failed\")\n\t}\n\n\t// Send response msg back to chaincode. GetState will not trigger event\n\treturn &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: payloadBytes, Txid: msg.Txid, ChannelId: msg.ChannelId}, nil\n}\n\nfunc (h *Handler) HandleGetPrivateDataHash(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error) {\n\tgetState := &pb.GetState{}\n\terr := proto.Unmarshal(msg.Payload, getState)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"unmarshal failed\")\n\t}\n\n\tvar res []byte\n\tnamespaceID := txContext.NamespaceID\n\tcollection := getState.Collection\n\tchaincodeLogger.Debugf(\"[%s] getting private data hash for chaincode %s, key %s, channel %s\", shorttxid(msg.Txid), namespaceID, getState.Key, txContext.ChannelID)\n\tif txContext.IsInitTransaction {","sourceCodeStart":728,"sourceCodeEnd":764,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/handler.go#L728-L764","documentation":"After fetching the values, the handler serializes pb.GetStateMultipleResult back to the chaincode with proto.Marshal. If Marshal fails (extremely rare; e.g. internal protobuf state corruption), the error is wrapped with 'marshal failed' and returned to the shim as an ERROR message. This is a server-side serialization failure, not caused by user input format.","triggerScenarios":"proto.Marshal(&pb.GetStateMultipleResult{Values: res}) fails — practically only when protobuf internal marshaling errors (e.g. nested message set to an invalid state) or resource/size issues occur.","commonSituations":"Very rare in practice; seen with corrupted protobuf runtime, exotic value bytes, or version-skewed generated code between the peer's protos and its protoc-gen-go runtime.","solutions":["Rebuild the peer with consistent, pinned protobuf/gogo-protobuf versions.","Check the fetched values res for nil sub-messages or invalid byte slices that confuse the marshaller.","Upgrade Hyperledger Fabric to a version with matching generated pb code.","Inspect peer logs for the underlying wrapped error for the exact cause."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":"func marshalableResult(values [][]byte) bool { _, err := proto.Marshal(&pb.GetStateMultipleResult{Values: values}); return err == nil }","tryCatchPattern":"payload, err := stub.GetStateByMultipleKeys(collection, keys)\nif err != nil && strings.Contains(err.Error(), \"marshal failed\") {\n    // retry once; if persistent, escalate to peer upgrade\n    return retryGetState(keys)\n}","preventionTips":["Keep peer binaries and vendored protobuf runtimes consistent and up to date.","Avoid exotic/nil sub-values in state bytes.","Escalate persistent occurrences as a peer bug with logs attached."],"tags":["hyperledger-fabric","protobuf","serialization"],"backgroundTag":"protobuf-marshal-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"}