jeessy2/ddns-go · error

failed to get record: %w

Error message

failed to get record: %w

What it means

updateRecord wraps any failure from h.getRecord() (which paginates /domains/{id}/records looking for an existing record for the subdomain+type) with this message. It means fetching the existing record list failed — network error, non-zero API code, or JSON parse failure in getRecord. Note: getRecord returning (nil, nil) when no record exists is NOT an error; the code then creates the record.

Source

Thrown at dns/hipmdnsmgr.go:152

	baseURL := h.DNS.ID
	if baseURL == "" {
		baseURL = hipmDnsMgrEndpoint
	}
	apiToken := h.DNS.Secret
	if apiToken == "" {
		return fmt.Errorf("API token cannot be empty")
	}

	// Get domain ID
	domainID, err := h.getDomainID(baseURL, apiToken, domain.DomainName)
	if err != nil {
		return fmt.Errorf("failed to get domain ID: %w", err)
	}

	// Get existing record
	record, err := h.getRecord(baseURL, apiToken, domainID, domain.SubDomain, recordType)
	if err != nil {
		return fmt.Errorf("failed to get record: %w", err)
	}

	ttl, _ := strconv.Atoi(h.TTL)
	if ttl == 0 {
		ttl = 600
	}

	if record != nil {
		// Update existing record
		return h.updateExistingRecord(baseURL, apiToken, domainID, record.ID, domain.SubDomain, recordType, ipAddr, ttl)
	}
	// Create new record
	return h.createRecord(baseURL, apiToken, domainID, domain.SubDomain, recordType, ipAddr, ttl)
}

// getHeaders 获取请求头
// 参考 dnsmgr.ts 中的 getHeaders() 方法
func (h *HiPMDnsMgr) getHeaders(apiToken string) map[string]string {

View on GitHub (pinned to 5874c2e666)

Solutions

  1. Read the wrapped cause: 'paginated record query API error' means auth/permission — fix the token or its domain permissions
  2. Confirm the previous 'failed to get domain ID' step succeeded (a bogus domainID makes record queries fail)
  3. Verify the API still returns {"total":..,"list":[...]} for /domains/{id}/records; adjust for API shape changes
  4. Check connectivity/proxy for intermittent 'paginated record query failed' network causes
  5. Retry the DDNS update — pagination spans multiple requests, so transient blips can abort it

Example fix

// before
apiToken := "expired-token"
// after: regenerate the token in DNSMgr and update the ddns-go Secret
apiToken := "<freshly generated DNSMgr API token>"
Defensive patterns

Strategy: try-catch

Validate before calling

// verify token can list records for the domain before relying on updates
req, _ := http.NewRequest("GET", base+"/api/domains/1/records?page=1&pageSize=1", nil)
req.Header.Set("Authorization", "Bearer "+apiToken)
resp, err := http.DefaultClient.Do(req)
if err != nil || resp.StatusCode != 200 {
    return fmt.Errorf("record endpoint unreachable or unauthorized")
}
resp.Body.Close()

Try / catch

if err := provider.AddUpdateDomainRecords(); err != nil {
    var wrapped interface{ Unwrap() error }
    if errors.As(err, &target) && strings.Contains(err.Error(), "API error") {
        // auth/permission problem: refresh token and retry once
        refreshTokenAndRetry()
    } else {
        log.Printf("transient record lookup failure, will retry next cycle: %v", err)
    }
}

Prevention

When it happens

Trigger: Any getRecord error during addUpdateDomainRecords -> updateRecord: HTTP failure on /domains/{domainID}/records, API returning code != 0 (e.g. auth or permission problem on that domain), or response Data that doesn't unmarshal into DnsMgrRecordList {total, list}.

Common situations: Token lacks permission for the specific domain's records; an invalid domainID (0) was passed through after a domain lookup failure; API upgraded and record-list response shape changed so json.Unmarshal into DnsMgrRecordList fails; transient network errors mid-pagination.

Related errors


AI-assisted analysis of jeessy2/ddns-go@5874c2e666 (2026-09-03). Data as JSON: /api/errors/d9bbcd80b43b54fb. Report an issue: GitHub.