jeessy2/ddns-go · error
unknown response data format: %T
Error message
unknown response data format: %T
What it means
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.
Source
Thrown at dns/hipmdnsmgr.go:267
}
switch v := rawData.(type) {
case []interface{}:
jsonData, _ := json.Marshal(v)
if err := json.Unmarshal(jsonData, &domains); err != nil {
return 0, fmt.Errorf("failed to parse domain list: %w", err)
}
case map[string]interface{}:
if listData, ok := v["list"]; ok {
jsonData, _ := json.Marshal(listData)
if err := json.Unmarshal(jsonData, &domains); err != nil {
return 0, fmt.Errorf("failed to parse domain list: %w", err)
}
} else {
return 0, fmt.Errorf("invalid response format: missing list field")
}
default:
return 0, fmt.Errorf("unknown response data format: %T", rawData)
}
// Check if exact match is found
for _, d := range domains {
if d.Name == domainName {
return d.ID, nil
}
}
// Method 2: If keyword query not found, use list matching as fallback (compatible with old API)
// Paginate through all domains to find the target
const pageSize = 100
currentPage := 1
for {
path := fmt.Sprintf("/domains?page=%d&pageSize=%d", currentPage, pageSize)
apiResp, err := h.request(baseURL, apiToken, "GET", path, nil)
if err != nil {View on GitHub (pinned to 5874c2e666)
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
Example fix
// before (server)
{"code":0,"data":null,"msg":"ok"}
// after (client guard)
if rawData == nil {
domains = nil // treat as empty result instead of erroring
} else {
switch v := rawData.(type) { ... }
} Defensive patterns
Strategy: type-guard
Type guard
func isJSONContainer(data json.RawMessage) bool {
var v interface{}
if err := json.Unmarshal(data, &v); err != nil {
return false
}
switch v.(type) {
case []interface{}, map[string]interface{}:
return true
default:
return false
}
} Try / catch
if err != nil && strings.Contains(err.Error(), "unknown response data format") {
log.Printf("DNSMgr data field is a scalar/null; server or routing misconfiguration: %v", err)
// verify baseURL and retry after server fix
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.
Related errors
- invalid response format: missing list field
- failed to parse domain list: %w
- dnsla 请求失败,状态码: %d, 响应: %s
- failed to get domain ID: %w
- failed to get record: %w
AI-assisted analysis of jeessy2/ddns-go@5874c2e666 (2026-09-03).
Data as JSON: /api/errors/2a7c11d75af21ffe.
Report an issue: GitHub.