{"record":{"id":"8c2c8061b2f91d4d","repo":"jeessy2/ddns-go","slug":"dnsla-w-8c2c80","errorCode":null,"errorMessage":"创建 dnsla 记录列表请求失败: %w","messagePattern":"创建 dnsla 记录列表请求失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dns/dnsla.go","lineNumber":260,"sourceCode":"}\n\n// 获得域名记录列表\nfunc (dnsla *Dnsla) getRecordList(domain *config.Domain, typ string) (result []byte, err error) {\n\trecordTypeInt := \"1\"\n\tif typ == \"AAAA\" {\n\t\trecordTypeInt = \"28\"\n\t}\n\tparams := domain.GetCustomParams()\n\tparams.Set(\"domain\", domain.DomainName)\n\tparams.Set(\"host\", domain.GetSubDomain())\n\tparams.Set(\"type\", recordTypeInt)\n\tparams.Set(\"pageIndex\", \"1\")\n\tparams.Set(\"pageSize\", \"999\")\n\n\turl := recordList + \"?\" + params.Encode()\n\treq, err := http.NewRequest(\"GET\", url, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"创建 dnsla 记录列表请求失败: %w\", err)\n\t}\n\n\tbyteBuff := []byte(dnsla.DNS.ID + \":\" + dnsla.DNS.Secret)\n\ttoken := \"Basic \" + base64.StdEncoding.EncodeToString(byteBuff)\n\t// 设置 Headers\n\treq.Header.Set(\"Authorization\", token)\n\n\t// 发送请求\n\tclient := dnsla.httpClient\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"请求 dnsla 记录列表失败: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\t// 读取响应\n\tresult, err = io.ReadAll(resp.Body)\n\tif err != nil {","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/jeessy2/ddns-go/blob/5874c2e6667c69357ab95079421131104bd3fcae/dns/dnsla.go#L242-L278","documentation":"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.","triggerScenarios":"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().","commonSituations":"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.","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"],"exampleFix":"// before\nurl := recordList + \"?\" + params.Encode()\nreq, err := http.NewRequest(\"GET\", url, nil)\nif err != nil {\n    return nil, fmt.Errorf(\"创建 dnsla 记录列表请求失败: %w\", err)\n}\n// after\nurl := recordList + \"?\" + params.Encode()\nif _, perr := url.Parse(url); perr != nil {\n    return nil, fmt.Errorf(\"dnsla 记录列表 URL 无效 %q: %w\", url, perr)\n}\nreq, err := http.NewRequest(\"GET\", url, nil)\nif err != nil {\n    return nil, fmt.Errorf(\"创建 dnsla 记录列表请求失败: %w\", err)\n}","handlingStrategy":"validation","validationCode":"u, err := url.Parse(recordList)\nif err != nil || u.Scheme == \"\" || u.Host == \"\" {\n    return fmt.Errorf(\"dnsla endpoint URL 无效: %q (%v)\", recordList, err)\n}","typeGuard":"func isValidURL(s string) bool {\n    u, err := url.Parse(s)\n    return err == nil && u.Scheme != \"\" && u.Host != \"\"\n}","tryCatchPattern":"if err != nil {\n    return nil, fmt.Errorf(\"创建 dnsla 记录列表请求失败: %w\", err)\n}\n// 调用方: \nrecords, err := getRecordList(...)\nif err != nil {\n    log.Printf(\"dnsla 记录列表请求构建失败: %v\", err)\n    return err\n}","preventionTips":["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"],"tags":["http","request-construction","dnsla","url"],"backgroundTag":"malformed-request-url","analyzedSha":"5874c2e6667c69357ab95079421131104bd3fcae","analyzedAt":"2026-09-03T15:41:16.799Z","contentChangedAt":"2026-09-03T15:41:16.799Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}