jeessy2/ddns-go · error
创建 dnsla 记录列表请求失败: %w
Error message
创建 dnsla 记录列表请求失败: %w
What it means
This error is thrown in getRecordList when http.NewRequest fails to construct the GET request that fetches the DNS record list from the dnsla API. The wrapping preserves the underlying cause (usually an invalid URL from bad parameters). It almost always indicates a malformed request URL rather than a network or credentials problem.
Source
Thrown at dns/dnsla.go:260
}
// 获得域名记录列表
func (dnsla *Dnsla) getRecordList(domain *config.Domain, typ string) (result []byte, err error) {
recordTypeInt := "1"
if typ == "AAAA" {
recordTypeInt = "28"
}
params := domain.GetCustomParams()
params.Set("domain", domain.DomainName)
params.Set("host", domain.GetSubDomain())
params.Set("type", recordTypeInt)
params.Set("pageIndex", "1")
params.Set("pageSize", "999")
url := recordList + "?" + params.Encode()
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, fmt.Errorf("创建 dnsla 记录列表请求失败: %w", err)
}
byteBuff := []byte(dnsla.DNS.ID + ":" + dnsla.DNS.Secret)
token := "Basic " + base64.StdEncoding.EncodeToString(byteBuff)
// 设置 Headers
req.Header.Set("Authorization", token)
// 发送请求
client := dnsla.httpClient
resp, err := client.Do(req)
if err != nil {
return nil, fmt.Errorf("请求 dnsla 记录列表失败: %w", err)
}
defer resp.Body.Close()
// 读取响应
result, err = io.ReadAll(resp.Body)
if err != nil {View on GitHub (pinned to 5874c2e666)
Solutions
- Inspect the wrapped error's message to see which part of the URL http.NewRequest rejected
- Print or log the value of recordList and params.Encode() before building the request to spot invalid characters
- Verify the dnsla API endpoint constant has no whitespace, newline, or invalid characters
- If the URL is fine, check for control characters in domain/param values passed in from the caller
Example fix
// before
url := recordList + "?" + params.Encode()
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, fmt.Errorf("创建 dnsla 记录列表请求失败: %w", err)
}
// after
url := recordList + "?" + params.Encode()
if _, perr := url.Parse(url); perr != nil {
return nil, fmt.Errorf("dnsla 记录列表 URL 无效 %q: %w", url, perr)
}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, fmt.Errorf("创建 dnsla 记录列表请求失败: %w", err)
} Defensive patterns
Strategy: validation
Validate before calling
u, err := url.Parse(recordList)
if err != nil || u.Scheme == "" || u.Host == "" {
return fmt.Errorf("dnsla endpoint URL 无效: %q (%v)", recordList, err)
} Type guard
func isValidURL(s string) bool {
u, err := url.Parse(s)
return err == nil && u.Scheme != "" && u.Host != ""
} Try / catch
if err != nil {
return nil, fmt.Errorf("创建 dnsla 记录列表请求失败: %w", err)
}
// 调用方:
records, err := getRecordList(...)
if err != nil {
log.Printf("dnsla 记录列表请求构建失败: %v", err)
return err
} Prevention
- Keep endpoint constants free of whitespace and trailing slashes/newlines
- Validate provider config (endpoint overrides) at startup
- Log the full URL when request construction fails to speed up diagnosis
When it happens
Trigger: http.NewRequest returns an error, which for this call only happens when the constructed URL (recordList + '?' + params.Encode()) is unparseable — e.g. recordList endpoint constant is misconfigured or params contain characters that break URL parsing after Encode().
Common situations: A patched or forked endpoint URL containing spaces/invalid characters; custom build where the dnsla API base URL was overridden with an invalid value; unit-test stubs injecting a malformed endpoint.
Related errors
AI-assisted analysis of jeessy2/ddns-go@5874c2e666 (2026-09-03).
Data as JSON: /api/errors/8c2c8061b2f91d4d.
Report an issue: GitHub.