{"record":{"id":"cd6cd82e30e98167","repo":"larksuite/cli","slug":"download-transport-received-a-nil-request","errorCode":null,"errorMessage":"download transport received a nil request","messagePattern":"download transport received a nil request","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/validate/url.go","lineNumber":202,"sourceCode":"\t}\n\treturn t.base.RoundTrip(req)\n}\n\ntype selectedDownloadProxyKey struct{}\n\ntype proxyAwareDownloadTransport struct {\n\tselectProxy func(*http.Request) (*url.URL, error)\n\tdirect      http.RoundTripper\n\tproxied     *http.Transport\n\tlookupIP    downloadLookupIPFunc\n\n\tmu                 sync.Mutex\n\tproxiedByTLSServer map[string]*http.Transport\n}\n\nfunc (t *proxyAwareDownloadTransport) RoundTrip(req *http.Request) (*http.Response, error) {\n\tif req == nil || req.URL == nil {\n\t\treturn nil, fmt.Errorf(\"download transport received a nil request\")\n\t}\n\tproxyURL, err := t.selectProxy(req)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif proxyURL == nil {\n\t\treturn t.direct.RoundTrip(req)\n\t}\n\n\ttargetIPs, err := resolveDownloadHost(req.Context(), req.URL.Hostname(), t.lookupIP)\n\tif err != nil {\n\t\treturn nil, errs.NewSecurityPolicyError(\n\t\t\terrs.SubtypeAccessDenied,\n\t\t\t\"blocked download target: %v\",\n\t\t\terr,\n\t\t).WithCause(err)\n\t}\n\tif strings.EqualFold(req.URL.Scheme, \"http\") && net.ParseIP(req.URL.Hostname()) == nil {","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/validate/url.go#L184-L220","documentation":"proxyAwareDownloadTransport.RoundTrip guards against being invoked with a nil *http.Request or a request with a nil URL (internal/validate/url.go:202) and returns this error instead of panicking. This is an internal invariant: the http.Client stack should never dispatch a nil request to a RoundTripper, so hitting this indicates the transport is being used outside the normal client flow or a caller constructed/modified requests incorrectly.","triggerScenarios":"Calling RoundTrip directly on a proxyAwareDownloadTransport (obtained via NewDownloadHTTPClient's transport chain) with a nil request or a request whose URL field is nil; misuse in tests or custom client code that bypasses http.Client.","commonSituations":"Custom middleware or test harnesses invoking transport.RoundTrip(nil); wrapping the download transport in another RoundTripper that drops or fails to populate the request; programming errors when hand-assembling *http.Request without a URL.","solutions":["Always issue requests through the http.Client returned by NewDownloadHTTPClient rather than calling RoundTrip directly.","When calling RoundTrip manually, ensure the *http.Request is non-nil and constructed with http.NewRequest (which always sets URL).","Audit any wrapping RoundTripper so it forwards the original request and never passes nil or strips the URL."],"exampleFix":"// before\nresp, err := transport.RoundTrip(nil)\n// after\nreq, _ := http.NewRequestWithContext(ctx, http.MethodGet, \"https://example.com/file\", nil)\nresp, err := client.Do(req)","handlingStrategy":"type-guard","validationCode":"if req == nil || req.URL == nil {\n    return fmt.Errorf(\"request and URL must be set before invoking transport\")\n}","typeGuard":"func isUsableHTTPRequest(req *http.Request) bool {\n    return req != nil && req.URL != nil\n}","tryCatchPattern":"if !isUsableHTTPRequest(req) {\n    return fmt.Errorf(\"cannot send nil request to download transport\")\n}\nresp, err := transport.RoundTrip(req)\nif err != nil {\n    if strings.Contains(err.Error(), \"nil request\") {\n        return fmt.Errorf(\"transport misuse: %w\", err)\n    }\n    return err\n}","preventionTips":["Issue downloads via http.Client.Do/Get instead of calling RoundTrip directly.","Always build requests with http.NewRequestWithContext so URL is populated.","In custom RoundTripper wrappers, forward the request as-is and never pass nil."],"tags":["http","transport","nil-check","internal"],"backgroundTag":"nil-request","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}