{"record":{"id":"2a7c11d75af21ffe","repo":"jeessy2/ddns-go","slug":"unknown-response-data-format-t","errorCode":null,"errorMessage":"unknown response data format: %T","messagePattern":"unknown response data format: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dns/hipmdnsmgr.go","lineNumber":267,"sourceCode":"\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\n\t\t}\n\t}\n\n\t// Method 2: If keyword query not found, use list matching as fallback (compatible with old API)\n\t// Paginate through all domains to find the target\n\tconst pageSize = 100\n\tcurrentPage := 1\n\n\tfor {\n\t\tpath := fmt.Sprintf(\"/domains?page=%d&pageSize=%d\", currentPage, pageSize)\n\t\tapiResp, err := h.request(baseURL, apiToken, \"GET\", path, nil)\n\t\tif err != nil {","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/jeessy2/ddns-go/blob/5874c2e6667c69357ab95079421131104bd3fcae/dns/hipmdnsmgr.go#L249-L285","documentation":"The format-detection switch in getDomainID handles JSON arrays and objects; anything else (number, bool, string, null surfaced as nil) hits the default case. This means the API's data field is of a fundamentally unexpected JSON type, indicating a broken or incompatible server response.","triggerScenarios":"GET /domains keyword query returns code==0 with data being a scalar (true, 1, \"ok\") or null instead of an array/object — e.g. server responding with a bare success value or an error string inside a code==0 envelope.","commonSituations":"Reverse proxy or API gateway replacing the body; server bug emitting \"data\": null on empty results in some versions; wrong baseURL (DNS.ID) pointing at a non-DNSMgr service that happens to return code==0 JSON.","solutions":["Curl the endpoint to see the raw data type returned","Fix the server so empty results return [] or {\"list\":[]} instead of null/scalars","Verify DNS.ID points at the real DNSMgr base URL, not another JSON API","Optionally treat data==null as an empty domain list in the client before the switch"],"exampleFix":"// before (server)\n{\"code\":0,\"data\":null,\"msg\":\"ok\"}\n// after (client guard)\nif rawData == nil {\n    domains = nil // treat as empty result instead of erroring\n} else {\n    switch v := rawData.(type) { ... }\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func isJSONContainer(data json.RawMessage) bool {\n    var v interface{}\n    if err := json.Unmarshal(data, &v); err != nil {\n        return false\n    }\n    switch v.(type) {\n    case []interface{}, map[string]interface{}:\n        return true\n    default:\n        return false\n    }\n}","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"unknown response data format\") {\n    log.Printf(\"DNSMgr data field is a scalar/null; server or routing misconfiguration: %v\", err)\n    // verify baseURL and retry after server fix\n}","preventionTips":["Verify DNS.ID points at the real DNSMgr API, not another JSON service","Check for gateways that replace error bodies with scalars while keeping code==0","Report/fix server versions that emit \"data\": null on empty domain lists"],"tags":["go","api","schema","parsing"],"backgroundTag":"unexpected-api-response-shape","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"}