siyuan-note/siyuan · error
nil response
Error message
nil response
What it means
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.
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
Example fix
// before
client = &http.Client{Transport: myCustomTransport} // may return (nil, nil)
// after
client = &http.Client{Transport: &ssrfGuard{Base: http.DefaultTransport}} // always returns a response or non-nil error Defensive patterns
Strategy: try-catch
Try / catch
if err != nil && err.Error() == "nil response" {
// treat as transient/internal: retry once, then escalate
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- attribute view [ ] template plan not found
- copied attribute view
- download failed:
- GitHub API returned status
- missing query param [u]
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/cdad3583c1d674b6.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/util/httprequest.go:338
var reqBody io.Reader
if body != "" && method != "GET" && method != "HEAD" {
reqBody = strings.NewReader(body)
}
req, err := http.NewRequest(method, rawURL, reqBody)
if err != nil {
return 0, "", "", errors.New("invalid request: " + err.Error())
}
for k, v := range headers {
req.Header.Set(k, v)
}
resp, err := ssrfSafeClient.Do(req)
if err != nil {
return 0, "", "", errors.New("request failed: " + err.Error())
}
if resp == nil {
return 0, "", "", errors.New("nil response")
}
defer resp.Body.Close()
statusCode = resp.StatusCode
contentType = resp.Header.Get("Content-Type")
maxReadBytes := int64(maxHTTPRequestBytes)
if !isTextContentType(contentType) {
maxReadBytes = maxHTTPRequestFileBytes
}
// ContentLength 为 -1(chunked)时跳过大小预检,交由 LimitReader 兜底截断。
if resp.ContentLength > maxReadBytes {
return statusCode, contentType, "", errors.New("response too large")
}
respBody, rerr := io.ReadAll(io.LimitReader(resp.Body, maxReadBytes))
if rerr != nil {
return statusCode, contentType, "", errors.New("read body failed: " + rerr.Error())View on GitHub (pinned to 9f775e8a12)