jeessy2/ddns-go · error

API token cannot be empty

Error message

API token cannot be empty

What it means

Thrown by HiPMDnsMgr.updateRecord when h.DNS.Secret is empty, i.e. the HiPM DNS Manager provider was configured without an API token. The library refuses to call getDomainID/update/create because every request requires token authentication. It is a configuration validation error raised before any network I/O.

Source

Thrown at dns/hipmdnsmgr.go:140

		if err != nil {
			util.Log("新增域名解析 %s 失败! 异常信息: %s", domain, err)
			domain.UpdateStatus = config.UpdatedFailed
		} else {
			util.Log("新增域名解析 %s 成功! IP: %s", domain, ipAddr)
			domain.UpdateStatus = config.UpdatedSuccess
		}
	}
}

// updateRecord 更新或创建 DNS 记录
func (h *HiPMDnsMgr) updateRecord(domain *config.Domain, ipAddr string, recordType string) error {
	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
	}

View on GitHub (pinned to 5874c2e666)

Solutions

  1. Open the ddns-go config and set Secret to your HiPM DNS Manager API token
  2. If editing the config JSON directly, ensure the dns section for this provider has "Secret": "<token>"
  3. Regenerate the API token from the HiPM DNS Manager console if you don't have one
  4. Restart/reload ddns-go after saving the config

Example fix

// before (config)
{
  "DNS": { "Name": "hipmdnsmgr", "ID": "", "Secret": "" }
}
// after (config)
{
  "DNS": { "Name": "hipmdnsmgr", "ID": "", "Secret": "your-api-token" }
}
Defensive patterns

Strategy: validation

Validate before calling

if strings.TrimSpace(h.DNS.Secret) == "" {
    return fmt.Errorf("HiPM DNS Manager API token must be configured in Secret field")
}

Type guard

func isMissingTokenErr(err error) bool {
    return strings.Contains(err.Error(), "API token cannot be empty")
}

Try / catch

err := h.updateRecord(domain, ipAddr, recordType)
if err != nil {
    if isMissingTokenErr(err) {
        // prompt user to configure Secret before retrying
    }
    return err
}

Prevention

When it happens

Trigger: addUpdateDomainRecords dispatches to updateRecord for a domain while the HiPMDnsMgr DNS config block has an empty Secret field.

Common situations: Missing secret/token in the ddns-go config file or web UI for the HiPM DNS Manager provider; user filled in ID (custom endpoint) but left Secret blank; config migration or hand-edited JSON dropped the secret field.

Related errors


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