{"record":{"id":"c04aba8b13c44562","repo":"hyperledger/fabric","slug":"nil-request","errorCode":null,"errorMessage":"nil request","messagePattern":"nil request","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"discovery/service.go","lineNumber":235,"sourceCode":"\t\tfor _, id := range peerIdentities {\n\t\t\t// Check peer exists in alive membership view\n\t\t\taliveInfo, exists := peerAliveInfo[string(id.PKIId)]\n\t\t\tif !exists {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tpeersForCurrentOrg[string(id.PKIId)] = &discovery.Peer{\n\t\t\t\tIdentity:       id.Identity,\n\t\t\t\tMembershipInfo: aliveInfo.Envelope,\n\t\t\t}\n\t\t}\n\t}\n\treturn peersByOrg\n}\n\n// validateStructure validates that the request contains all the needed fields and that they are computed correctly\nfunc validateStructure(ctx context.Context, request *discovery.SignedRequest, tlsEnabled bool, certHashFromContext certHashExtractor) (*discovery.Request, error) {\n\tif request == nil {\n\t\treturn nil, errors.New(\"nil request\")\n\t}\n\treq, err := protoext.SignedRequestToRequest(request)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"failed parsing request\")\n\t}\n\tif req.Authentication == nil {\n\t\treturn nil, errors.New(\"access denied, no authentication info in request\")\n\t}\n\tif len(req.Authentication.ClientIdentity) == 0 {\n\t\treturn nil, errors.New(\"access denied, client identity wasn't supplied\")\n\t}\n\tif !tlsEnabled {\n\t\treturn req, nil\n\t}\n\tcomputedHash := certHashFromContext(ctx)\n\tif len(computedHash) == 0 {\n\t\treturn nil, errors.New(\"client didn't send a TLS certificate\")\n\t}","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/discovery/service.go#L217-L253","documentation":"validateStructure rejects the discovery request outright when the SignedRequest pointer is nil. The discovery service cannot even attempt to parse or authenticate a nil request, so it fails fast with this sentinel error before any signature or identity checks.","triggerScenarios":"The gRPC handler Discover receives a nil *discovery.SignedRequest. Client-side, this happens when a caller passes nil to the discovery client's Send method or constructs a request object that was never initialized.","commonSituations":"Calling client.Send(ctx, nil) or forgetting to build a request (e.g. NewSignedRequest/ComputeHashtoSign flow skipped); a wrapper function that drops the request on an error path; miswired test harness passing nil.","solutions":["Ensure a *discovery.SignedRequest is constructed (via discovery.NewRequest().... and signing) before calling Send","Check your client code path for a branch that can pass a nil request to Send","If using a helper/wrapper, validate the request parameter is non-nil before dispatching","On the server this is a client bug — inspect client logs to find where the nil request originated"],"exampleFix":"// before\nvar req *discovery.SignedRequest\nresp, err := client.Send(ctx, req) // nil request\n// after\nreq := discovery.NewRequest().SetAuthentication(clientIdentity, tlsCertHash).SetPeersInterests(...).ToSignedRequest()\nsignedReq, err := req.Sign(key)\nif err != nil { return err }\nresp, err := client.Send(ctx, signedReq)","handlingStrategy":"validation","validationCode":"if signedReq == nil {\n    return errors.New(\"discovery: signed request is nil; build and sign a request first\")\n}","typeGuard":"func isNilRequest(r *discovery.SignedRequest) bool { return r == nil }","tryCatchPattern":"resp, err := client.Send(ctx, signedReq)\nif err != nil {\n    if strings.Contains(err.Error(), \"nil request\") {\n        return nil, fmt.Errorf(\"programming error: request never built: %w\", err)\n    }\n    return nil, err\n}","preventionTips":["Always construct requests through the SDK's discovery client, never pass raw nils","Assert non-nil request in wrapper functions before Send","Cover the Send call path with a unit test using a real signed request","Enable linters (e.g. nilness) that flag nil-pointer arguments"],"tags":["hyperledger-fabric","discovery-service","nil-request","input-validation"],"backgroundTag":"nil-request","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"}