{"record":{"id":"38622bf2923f2cea","repo":"jeessy2/ddns-go","slug":"failed-to-parse-domain-list-w","errorCode":null,"errorMessage":"failed to parse domain list: %w","messagePattern":"failed to parse domain list: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dns/hipmdnsmgr.go","lineNumber":255,"sourceCode":"\t}\n\n\tif apiResp.Code != 0 {\n\t\treturn 0, fmt.Errorf(\"API error: %s\", apiResp.Msg)\n\t}\n\n\tvar domains []DnsMgrDomain\n\n\t// Smart detection: support both array and object formats\n\tvar rawData interface{}\n\tif err := json.Unmarshal(apiResp.Data, &rawData); err != nil {\n\t\treturn 0, fmt.Errorf(\"failed to parse response data: %w\", err)\n\t}\n\n\tswitch v := rawData.(type) {\n\tcase []interface{}:\n\t\tjsonData, _ := json.Marshal(v)\n\t\tif err := json.Unmarshal(jsonData, &domains); err != nil {\n\t\t\treturn 0, fmt.Errorf(\"failed to parse domain list: %w\", err)\n\t\t}\n\tcase map[string]interface{}:\n\t\tif listData, ok := v[\"list\"]; ok {\n\t\t\tjsonData, _ := json.Marshal(listData)\n\t\t\tif err := json.Unmarshal(jsonData, &domains); err != nil {\n\t\t\t\treturn 0, fmt.Errorf(\"failed to parse domain list: %w\", err)\n\t\t\t}\n\t\t} else {\n\t\t\treturn 0, fmt.Errorf(\"invalid response format: missing list field\")\n\t\t}\n\tdefault:\n\t\treturn 0, fmt.Errorf(\"unknown response data format: %T\", rawData)\n\t}\n\n\t// Check if exact match is found\n\tfor _, d := range domains {\n\t\tif d.Name == domainName {\n\t\t\treturn d.ID, nil","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/jeessy2/ddns-go/blob/5874c2e6667c69357ab95079421131104bd3fcae/dns/hipmdnsmgr.go#L237-L273","documentation":"When the keyword-query response data is a JSON array, getDomainID re-marshals it and unmarshals into []DnsMgrDomain; if the array elements don't match the DnsMgrDomain field types (id/account_id/record_count expected numbers; name/third_id strings), this wrapped error is returned.","triggerScenarios":"The /domains keyword search returns a top-level JSON array whose items have mismatched types, e.g. id as string \"12\" instead of number, causing json.Unmarshal into []DnsMgrDomain to fail.","commonSituations":"DNSMgr server version emitting string-typed IDs; a different compatible API (alternate backend) with a slightly different domain schema; custom server forks returning extra/renamed fields with wrong types.","solutions":["Curl the endpoint and check the array element types against DnsMgrDomain (numeric id, string name)","If the server returns string IDs, change DnsMgrDomain.ID to json.Number or string and convert","Align the DNSMgr server version with the schema this client expects","Check the wrapped %w message — it names the exact field and Go type mismatch"],"exampleFix":"// before (server response)\n[{\"id\":\"12\",\"name\":\"example.com\"}]\n// after (client fix)\ntype DnsMgrDomain struct {\n    ID json.Number `json:\"id\"`\n    Name string `json:\"name\"`\n    ...\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func isDomainArray(data json.RawMessage) ([]DnsMgrDomain, error) {\n    var arr []map[string]interface{}\n    if err := json.Unmarshal(data, &arr); err != nil {\n        return nil, err\n    }\n    for _, m := range arr {\n        if _, ok := m[\"id\"].(float64); !ok {\n            return nil, fmt.Errorf(\"domain id is not numeric\")\n        }\n        if _, ok := m[\"name\"].(string); !ok {\n            return nil, fmt.Errorf(\"domain name is not a string\")\n        }\n    }\n    var domains []DnsMgrDomain\n    b, _ := json.Marshal(arr)\n    return domains, json.Unmarshal(b, &domains)\n}","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"failed to parse domain list\") {\n    log.Printf(\"domain schema mismatch; inspect /api/domains item types: %v\", err)\n    // fall back to manual field mapping via map[string]interface{}\n}","preventionTips":["Keep DNSMgr server and ddns-go client versions schema-compatible","Use json.Number or string+convert for ID fields to tolerate string-typed IDs","Add a unit test unmarshaling a captured real API response into DnsMgrDomain"],"tags":["go","json","parsing","schema"],"backgroundTag":"json-unmarshal-failed","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"}