{"record":{"id":"cdad3583c1d674b6","repo":"siyuan-note/siyuan","slug":"nil-response","errorCode":null,"errorMessage":"nil response","messagePattern":"nil response","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/httprequest.go","lineNumber":338,"sourceCode":"\n\tvar reqBody io.Reader\n\tif body != \"\" && method != \"GET\" && method != \"HEAD\" {\n\t\treqBody = strings.NewReader(body)\n\t}\n\treq, err := http.NewRequest(method, rawURL, reqBody)\n\tif err != nil {\n\t\treturn 0, \"\", \"\", errors.New(\"invalid request: \" + err.Error())\n\t}\n\tfor k, v := range headers {\n\t\treq.Header.Set(k, v)\n\t}\n\n\tresp, err := ssrfSafeClient.Do(req)\n\tif err != nil {\n\t\treturn 0, \"\", \"\", errors.New(\"request failed: \" + err.Error())\n\t}\n\tif resp == nil {\n\t\treturn 0, \"\", \"\", errors.New(\"nil response\")\n\t}\n\tdefer resp.Body.Close()\n\n\tstatusCode = resp.StatusCode\n\tcontentType = resp.Header.Get(\"Content-Type\")\n\n\tmaxReadBytes := int64(maxHTTPRequestBytes)\n\tif !isTextContentType(contentType) {\n\t\tmaxReadBytes = maxHTTPRequestFileBytes\n\t}\n\t// ContentLength 为 -1（chunked）时跳过大小预检，交由 LimitReader 兜底截断。\n\tif resp.ContentLength > maxReadBytes {\n\t\treturn statusCode, contentType, \"\", errors.New(\"response too large\")\n\t}\n\n\trespBody, rerr := io.ReadAll(io.LimitReader(resp.Body, maxReadBytes))\n\tif rerr != nil {\n\t\treturn statusCode, contentType, \"\", errors.New(\"read body failed: \" + rerr.Error())","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/httprequest.go#L320-L356","documentation":"HTTPRequest defensively treats a nil *http.Response as an error. In Go's net/http a nil response normally accompanies a non-nil error, so reaching this branch indicates the transport returned no error yet no response object — an unexpected client state. The function aborts with \"nil response\" rather than dereferencing resp.","triggerScenarios":"Calling HTTPRequest when the underlying client returns (nil, nil) — practically only seen with a custom/nonstandard RoundTripper inside ssrfSafeClient or misuse of a mocked client; standard net/http never yields err==nil with resp==nil.","commonSituations":"A modified or wrapped http.Client transport (proxy helpers, test doubles) returning nil/nil; build configurations with a patched networking stack; otherwise this is a rare internal-invariant failure rather than a user-triggerable condition.","solutions":["Retry the request — if it recurs, the transport client has been customized or broken","Inspect any custom http.RoundTripper or client wrappers compiled into ssrfSafeClient for a path returning (nil, nil)","Check the request construction upstream (method, URL, body) — malformed requests can surface as odd client states","Report/fix as an internal invariant violation if it reproduces with the stock client"],"exampleFix":"// before\nclient = &http.Client{Transport: myCustomTransport} // may return (nil, nil)\n// after\nclient = &http.Client{Transport: &ssrfGuard{Base: http.DefaultTransport}} // always returns a response or non-nil error","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil && err.Error() == \"nil response\" {\n    // treat as transient/internal: retry once, then escalate\n}","preventionTips":["Do not replace or wrap the stock http transport inside ssrfSafeClient","Ensure custom RoundTrippers always return either a non-nil response or a non-nil error","Report persistent occurrences as an internal bug"],"tags":["http","null-response","go","invariant"],"backgroundTag":"unexpected-response-shape","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}