{"record":{"id":"f04d7bd1e83f57a5","repo":"hyperledger/fabric","slug":"failed-creating-request","errorCode":null,"errorMessage":"failed creating request","messagePattern":"failed creating request","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"discovery/cmd/endorsers.go","lineNumber":107,"sourceCode":"\t}\n\tcc2collections, err := ccAndCol.parseInput()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tvar ccCalls []*peer.ChaincodeCall\n\n\tfor _, cc := range *ccAndCol.Chaincodes {\n\t\tccCalls = append(ccCalls, &peer.ChaincodeCall{\n\t\t\tName:            cc,\n\t\t\tCollectionNames: cc2collections[cc],\n\t\t\tNoPrivateReads:  ccAndCol.noPrivateReads(cc),\n\t\t})\n\t}\n\n\treq, err := discoveryclient.NewRequest().OfChannel(channel).AddEndorsersQuery(&peer.ChaincodeInterest{Chaincodes: ccCalls})\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"failed creating request\")\n\t}\n\n\tres, err := pc.stub.Send(server, conf, req)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn pc.parser.ParseResponse(channel, res)\n}\n\n// EndorserResponseParser parses endorsement responses from the peer\ntype EndorserResponseParser struct {\n\tio.Writer\n}\n\n// ParseResponse parses the given response for the given channel\nfunc (parser *EndorserResponseParser) ParseResponse(channel string, res ServiceResponse) error {\n\trawResponse := res.Raw()","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/discovery/cmd/endorsers.go#L89-L125","documentation":"While building the endorsers query, the library calls discoveryclient.NewRequest().OfChannel(...).AddEndorsersQuery(...). AddEndorsersQuery returns an error (e.g. a chaincode call has no name, or protobuf marshalling of ChaincodeInterest fails), which Execute wraps with \"failed creating request\" via errors.Wrap. The original cause is preserved in the wrapped error chain.","triggerScenarios":"Adding an endorsers query with a ChaincodeInterest containing ChaincodeCalls with empty names or invalid data, or proto serialization failure of the interest structure.","commonSituations":"Chaincode names/collections sourced from empty flags or config; malformed chaincodesAndCollections input (empty cc name, missing collection names); constructing interest lists programmatically with partially filled structs.","solutions":["Inspect err.Unwrap()/cause of the wrapped error to see the underlying reason","Ensure every ChaincodeCall added has a non-empty Name and valid collection names","Validate the chaincode/collection inputs before building the request"],"exampleFix":"// before\nccCalls = append(ccCalls, &discovery.ChaincodeCall{Name: ccName}) // ccName may be \"\"\n// after\nif ccName == \"\" {\n    return errors.New(\"chaincode name required\")\n}\nccCalls = append(ccCalls, &discovery.ChaincodeCall{Name: ccName})","handlingStrategy":"try-catch","validationCode":"if ccName == \"\" || len(collections) == 0 {\n    return errors.New(\"chaincode name and collections must be set before AddEndorsersQuery\")\n}","typeGuard":"func callIsValid(call *discovery.ChaincodeCall) bool {\n    return call != nil && call.Name != \"\"\n}","tryCatchPattern":"req, err := discoveryclient.NewRequest().OfChannel(channel).AddEndorsersQuery(interest)\nif err != nil {\n    var cause error\n    for errors.Unwrap(err) != nil {\n        err = errors.Unwrap(err)\n    }\n    cause = err\n    return fmt.Errorf(\"request construction failed, cause: %v\", cause)\n}","preventionTips":["Validate ChaincodeCall structs (non-empty Name, valid collection names) before building interests","Unwrap wrapped errors to find the root cause","Log the full chaincode interest payload on failure"],"tags":["go","discovery","request-construction","wrapped-error"],"backgroundTag":"request-construction-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"}